@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
package/src/fetchWithCookies.ts
CHANGED
|
@@ -1,63 +1,154 @@
|
|
|
1
|
-
// noinspection JSUnusedGlobalSymbols
|
|
1
|
+
// noinspection JSUnusedGlobalSymbols,ExceptionCaughtLocallyJS
|
|
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 { cookieJarPromise } from "./CookieStore";
|
|
8
|
+
import UserAgent from "user-agents";
|
|
9
|
+
import { parsedArgs } from "./argv";
|
|
10
|
+
import { blue, redBright, yellow } from "colorette";
|
|
11
|
+
import { getMergedRenderedCookies } from "./getMergedRenderedCookies";
|
|
12
|
+
import { cookieSpecsFromUrl } from "./cookieSpecsFromUrl";
|
|
13
|
+
import CookieSpec from "./CookieSpec";
|
|
14
|
+
|
|
15
|
+
const userAgent = new UserAgent().toString();
|
|
16
|
+
|
|
17
|
+
interface FetchRequestInit {
|
|
18
|
+
url: RequestInfo | URL | string;
|
|
19
|
+
options?: RequestInit;
|
|
20
|
+
}
|
|
9
21
|
|
|
10
22
|
export async function fetchWithCookies(
|
|
11
|
-
url: RequestInfo | URL,
|
|
12
|
-
options: RequestInit | undefined = {}
|
|
13
|
-
|
|
23
|
+
url: RequestInfo | URL | string,
|
|
24
|
+
options: RequestInit | undefined = {},
|
|
25
|
+
fetch: Function = fetchImpl,
|
|
26
|
+
originalRequest: FetchRequestInit | undefined = undefined
|
|
27
|
+
): Promise<Response> {
|
|
28
|
+
const originalRequest1 = originalRequest || { url, options };
|
|
29
|
+
const headers: HeadersInit = {
|
|
30
|
+
"User-Agent": userAgent,
|
|
31
|
+
};
|
|
14
32
|
const defaultOptions: RequestInit = {
|
|
15
|
-
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",
|
|
18
|
-
},
|
|
33
|
+
headers,
|
|
19
34
|
redirect: "manual",
|
|
20
35
|
};
|
|
21
36
|
const url2: string = `${url}`;
|
|
22
37
|
const url1: URL = new URL(url2);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const newOptions1: RequestInit = merge(defaultOptions,
|
|
32
|
-
headers: {
|
|
33
|
-
Cookie: cookie,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
38
|
+
const cookieSpecs: CookieSpec[] = cookieSpecsFromUrl(url1);
|
|
39
|
+
headers["Cookie"] = await getMergedRenderedCookies(cookieSpecs).catch(
|
|
40
|
+
() => ""
|
|
41
|
+
);
|
|
42
|
+
if (parsedArgs["dump-request-headers"]) {
|
|
43
|
+
console.log(redBright("Request URL:"), url1.href);
|
|
44
|
+
console.log(blue("Request headers:"), headers);
|
|
45
|
+
}
|
|
46
|
+
const newOptions1: RequestInit = merge(defaultOptions, { headers }, options);
|
|
36
47
|
try {
|
|
37
|
-
const res: Response = await fetch(
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
const res: Response = await fetch(url1, newOptions1);
|
|
49
|
+
const headers: [string, string][] = [];
|
|
50
|
+
res.headers.forEach((value, key) => {
|
|
51
|
+
headers.push([key, value]);
|
|
52
|
+
});
|
|
53
|
+
for (const [key, value] of headers) {
|
|
54
|
+
if (key === "set-cookie") {
|
|
55
|
+
const cookieJar1 = await cookieJarPromise;
|
|
56
|
+
await cookieJar1.setCookie(value, url2);
|
|
57
|
+
if (parsedArgs.verbose) {
|
|
58
|
+
console.log(blue(`Set-Cookie:`), yellow(value), yellow(url2));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const newUrl: string = res.headers.get("location") ?? res.url;
|
|
64
|
+
// const sameHost = new URL(newUrl).host === url1.host;
|
|
65
|
+
if (res.status == 301 || res.status == 302) {
|
|
66
|
+
// follow the redirect
|
|
67
|
+
if (newUrl && newUrl !== url2) {
|
|
68
|
+
if (parsedArgs.verbose || parsedArgs["dump-response-headers"]) {
|
|
69
|
+
console.log(blue(`Redirected to `), yellow(newUrl));
|
|
70
|
+
}
|
|
71
|
+
return fetchWithCookies(
|
|
72
|
+
//
|
|
73
|
+
newUrl,
|
|
74
|
+
newOptions1,
|
|
75
|
+
fetch,
|
|
76
|
+
originalRequest1
|
|
77
|
+
//
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (res.status == 303 && newUrl && newUrl !== url2) {
|
|
82
|
+
// follow the redirect with GET
|
|
83
|
+
let newOptions2: RequestInit = {};
|
|
84
|
+
switch (newOptions1.method) {
|
|
85
|
+
case "POST":
|
|
86
|
+
case "PUT":
|
|
87
|
+
case "DELETE":
|
|
88
|
+
merge(newOptions2, newOptions1, { method: "GET" });
|
|
89
|
+
newOptions2.body = undefined; // TODO: is this needed?
|
|
90
|
+
break;
|
|
91
|
+
case "HEAD":
|
|
92
|
+
case "GET":
|
|
93
|
+
merge(newOptions2, newOptions1);
|
|
94
|
+
newOptions2.body = undefined; // TODO: is this needed?
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
merge(newOptions2, newOptions1);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (parsedArgs.verbose) {
|
|
101
|
+
console.log(blue(`Redirected to `), yellow(newUrl));
|
|
102
|
+
}
|
|
103
|
+
return fetchWithCookies(
|
|
104
|
+
//
|
|
105
|
+
newUrl,
|
|
106
|
+
newOptions2,
|
|
107
|
+
fetch,
|
|
108
|
+
originalRequest1
|
|
109
|
+
//
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const arrayBuffer1: Promise<ArrayBuffer> = res.arrayBuffer();
|
|
114
|
+
|
|
115
|
+
async function arrayBuffer(): Promise<ArrayBuffer> {
|
|
116
|
+
return arrayBuffer1;
|
|
41
117
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
118
|
+
|
|
119
|
+
async function buffer(): Promise<Buffer> {
|
|
120
|
+
return arrayBuffer().then(Buffer.from);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function text(): Promise<string> {
|
|
124
|
+
return buffer().then((buffer: Buffer) => buffer.toString("utf8"));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function json(): Promise<any> {
|
|
128
|
+
return text().then((text: string) => destr(text));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function formData(): Promise<FormData> {
|
|
132
|
+
const urlSearchParams: URLSearchParams = await text().then(
|
|
133
|
+
(text) => new URLSearchParams(text)
|
|
134
|
+
);
|
|
135
|
+
const formData = new FormData();
|
|
136
|
+
for (const [key, value] of urlSearchParams.entries()) {
|
|
137
|
+
formData.append(key, value);
|
|
138
|
+
}
|
|
139
|
+
return formData;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const res1: Response = res;
|
|
49
143
|
const source2 = {
|
|
50
|
-
status: res.status,
|
|
51
|
-
statusText: res.statusText,
|
|
52
|
-
headers: res.headers,
|
|
53
144
|
arrayBuffer,
|
|
54
|
-
buffer,
|
|
55
145
|
text,
|
|
56
146
|
json,
|
|
147
|
+
buffer,
|
|
57
148
|
formData,
|
|
58
149
|
//
|
|
59
150
|
};
|
|
60
|
-
return merge(
|
|
151
|
+
return merge(res1, source2);
|
|
61
152
|
} catch (e) {
|
|
62
153
|
throw e;
|
|
63
154
|
}
|
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,19 @@
|
|
|
1
|
-
import { queryCookies } from "./queryCookies";
|
|
2
|
-
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
3
1
|
import { groupBy } from "lodash";
|
|
4
2
|
import { resultsRendered } from "./resultsRendered";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
3
|
+
import { MultiCookieSpec } from "./CookieSpec";
|
|
4
|
+
import ExportedCookie from "./ExportedCookie";
|
|
5
|
+
import { comboQueryCookieSpec } from "./comboQueryCookieSpec";
|
|
7
6
|
|
|
8
7
|
export async function getGroupedRenderedCookies(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}: //
|
|
14
|
-
CookieSpec
|
|
15
|
-
): //
|
|
16
|
-
Promise<string[]> {
|
|
17
|
-
const cookies: ExportedCookie[] = await queryCookies(
|
|
18
|
-
{ name, domain },
|
|
19
|
-
new CompositeCookieQueryStrategy()
|
|
20
|
-
//
|
|
21
|
-
);
|
|
22
|
-
if (Array.isArray(cookies) && cookies.length > 0) {
|
|
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 {
|
|
8
|
+
cookieSpec: MultiCookieSpec
|
|
9
|
+
): Promise<string[]> {
|
|
10
|
+
const cookies: ExportedCookie[] = await comboQueryCookieSpec(cookieSpec);
|
|
11
|
+
if (cookies.length == 0) {
|
|
30
12
|
throw new Error("Cookie not found");
|
|
31
13
|
}
|
|
14
|
+
const groupedByFile = groupBy(cookies, (r: ExportedCookie) => r.meta?.file);
|
|
15
|
+
return Object.keys(groupedByFile).map((file: string) => {
|
|
16
|
+
const results: ExportedCookie[] = groupedByFile[file];
|
|
17
|
+
return resultsRendered(results);
|
|
18
|
+
});
|
|
32
19
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { resultsRendered } from "./resultsRendered";
|
|
2
|
+
import { comboQueryCookieSpec } from "./comboQueryCookieSpec";
|
|
3
|
+
import { MultiCookieSpec } from "./CookieSpec";
|
|
4
|
+
import ExportedCookie from "./ExportedCookie";
|
|
5
|
+
|
|
6
|
+
export async function getMergedRenderedCookies(
|
|
7
|
+
cookieSpec: MultiCookieSpec
|
|
8
|
+
): Promise<string> {
|
|
9
|
+
const cookies: ExportedCookie[] = await comboQueryCookieSpec(cookieSpec);
|
|
10
|
+
if (cookies.length > 0) {
|
|
11
|
+
return resultsRendered(cookies);
|
|
12
|
+
}
|
|
13
|
+
return "";
|
|
14
|
+
}
|
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;
|
package/src/queryCookies.ts
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import { env } from "./global";
|
|
2
1
|
import { uniqBy } from "lodash";
|
|
2
|
+
import { parsedArgs } from "./argv";
|
|
3
3
|
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
4
4
|
import CookieQueryStrategy from "./browsers/CookieQueryStrategy";
|
|
5
5
|
import isValidJwt from "./isValidJwt";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import CookieSpec from "./CookieSpec";
|
|
7
|
+
import ExportedCookie from "./ExportedCookie";
|
|
8
8
|
|
|
9
9
|
export async function queryCookies(
|
|
10
10
|
{ name, domain }: CookieSpec,
|
|
11
11
|
strategy: CookieQueryStrategy = new CompositeCookieQueryStrategy()
|
|
12
|
-
) {
|
|
12
|
+
): Promise<ExportedCookie[]> {
|
|
13
13
|
const results: ExportedCookie[] = await strategy.queryCookies(name, domain);
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const allCookies: ExportedCookie[] = uniqBy(results, JSON.stringify);
|
|
15
|
+
|
|
16
|
+
if (parsedArgs["require-jwt"]) {
|
|
17
|
+
const jwtCookies = [];
|
|
18
|
+
for (const result of allCookies) {
|
|
19
|
+
const value: string = result.value;
|
|
20
|
+
if (isValidJwt(value)) {
|
|
21
|
+
jwtCookies.push(result);
|
|
22
|
+
}
|
|
20
23
|
}
|
|
24
|
+
return parsedArgs["single"] ? [jwtCookies[0]] : jwtCookies;
|
|
25
|
+
} else {
|
|
26
|
+
return parsedArgs["single"] ? [allCookies[0]] : allCookies;
|
|
21
27
|
}
|
|
22
|
-
const resultsUniq = env.REQUIRE_JWT ? jwtCookies : results1;
|
|
23
|
-
return env.SINGLE ? [resultsUniq[0]] : resultsUniq;
|
|
24
28
|
}
|
package/src/resultsRendered.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { uniqBy } from "lodash";
|
|
2
|
-
import
|
|
1
|
+
import { orderBy, uniqBy } from "lodash";
|
|
2
|
+
import ExportedCookie from "./ExportedCookie";
|
|
3
3
|
|
|
4
4
|
export function resultsRendered(results: ExportedCookie[]) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// sort by name and expiry descending
|
|
6
|
+
// takes the latest expiry for each name
|
|
7
|
+
const orderedResults = orderBy(results, ["name", "expiry"], ["asc", "desc"]);
|
|
8
|
+
return uniqBy(orderedResults, (r: ExportedCookie) => r.name)
|
|
9
|
+
.map((r: ExportedCookie) => r.name + "=" + r.value)
|
|
7
10
|
.join("; ");
|
|
8
11
|
}
|
package/src/unpackHeaders.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
export function unpackHeaders(headerArgs: string[] | string) {
|
|
1
|
+
export function unpackHeaders(headerArgs: string[] | string | null) {
|
|
2
2
|
const headers: any = {};
|
|
3
|
+
if (headerArgs == null) {
|
|
4
|
+
return headers;
|
|
5
|
+
}
|
|
3
6
|
if (Array.isArray(headerArgs)) {
|
|
4
7
|
for (const h of headerArgs) {
|
|
5
8
|
const [key, value] = h.split("=");
|
|
6
9
|
headers[key] = value;
|
|
7
10
|
}
|
|
8
|
-
|
|
9
|
-
const [key, value] = headerArgs.split("=");
|
|
10
|
-
headers[key] = value;
|
|
11
|
+
return headers;
|
|
11
12
|
}
|
|
13
|
+
const [key, value] = headerArgs.split("=");
|
|
14
|
+
headers[key] = value;
|
|
12
15
|
return headers;
|
|
13
16
|
}
|
package/src/utils.ts
CHANGED
|
@@ -23,28 +23,3 @@ export async function execSimple(command: string): Promise<string> {
|
|
|
23
23
|
);
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
export function toStringOrNull(result: any) {
|
|
28
|
-
if (result == null) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
if (process.env.VERBOSE) {
|
|
32
|
-
console.log("result", result);
|
|
33
|
-
}
|
|
34
|
-
if (typeof result === "string" && result.length > 0) {
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
if (result.slice && result.toString) {
|
|
38
|
-
// noinspection JSCheckFunctionSignatures
|
|
39
|
-
return result.toString("utf8");
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function invalidString(input: any): boolean {
|
|
45
|
-
return typeof input !== "string" || input.length === 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function validString(input: any): input is string {
|
|
49
|
-
return typeof input == "string" && input.length > 0;
|
|
50
|
-
}
|
package/tsconfig.json
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
"include": [
|
|
3
|
-
"src/**.ts",
|
|
4
|
-
"src/**.tsx",
|
|
5
|
-
"src/**.js",
|
|
6
|
-
"src/**.jsx"
|
|
7
|
-
],
|
|
2
|
+
"include": ["src/**.ts", "src/**.tsx", "src/**.js", "src/**.jsx"],
|
|
8
3
|
"compilerOptions": {
|
|
9
4
|
"moduleResolution": "node",
|
|
10
5
|
"target": "es2021",
|
|
11
|
-
"types": [
|
|
12
|
-
|
|
13
|
-
],
|
|
14
|
-
"lib": [
|
|
15
|
-
"es2015",
|
|
16
|
-
"es2017",
|
|
17
|
-
"es2021",
|
|
18
|
-
"dom"
|
|
19
|
-
],
|
|
6
|
+
"types": ["node"],
|
|
7
|
+
"lib": ["es2015", "es2017", "es2021", "dom"],
|
|
20
8
|
"strict": true,
|
|
9
|
+
"skipDefaultLibCheck": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
21
11
|
"allowSyntheticDefaultImports": true,
|
|
12
|
+
"emitDeclarationOnly": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"module": "commonjs",
|
|
16
|
+
"outDir": "dist",
|
|
17
|
+
"outFile": "dist/types.d.ts"
|
|
22
18
|
}
|
|
23
19
|
}
|