@mherod/get-cookie 2.0.0-rc.30 → 2.0.0-rc.32
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/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/module.js +83 -51
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -6
- package/src/CookieStore.ts +1 -1
- package/src/FetchResponse.ts +1 -2
- package/src/FileCookieStore.ts +13 -10
- package/src/browsers/ChromeApplicationSupport.ts +1 -1
- package/src/browsers/ChromeCookieQueryStrategy.ts +4 -4
- package/src/browsers/CompositeCookieQueryStrategy.ts +28 -32
- package/src/browsers/CookieStoreQueryStrategy.ts +2 -2
- package/src/browsers/DoSqliteQueryWithTransform.ts +3 -3
- package/src/browsers/FirefoxCookieQueryStrategy.ts +3 -3
- package/src/browsers/decrypt.ts +4 -4
- package/src/browsers/getChromePassword.ts +1 -1
- package/src/cli.ts +3 -46
- package/src/cliQueryCookies.ts +62 -0
- package/src/comboQueryCookieSpec.ts +10 -13
- package/src/fetchWithCookies.ts +11 -13
- package/src/findAllFiles.ts +1 -1
- package/src/getChromeCookie.ts +2 -2
- package/src/getCookie.ts +2 -2
- package/src/getFirefoxCookie.ts +2 -2
- package/src/getGroupedRenderedCookies.ts +1 -1
- package/src/getMergedRenderedCookies.test.ts +25 -0
- package/src/getMergedRenderedCookies.ts +1 -1
- package/src/queryCookies.ts +5 -2
- package/src/util/flatMapAsync.ts +2 -2
- package/tsconfig.json +9 -2
package/src/fetchWithCookies.ts
CHANGED
|
@@ -4,10 +4,7 @@ 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 { cookieJarPromise } from "./CookieStore";
|
|
8
|
-
import UserAgent from "user-agents";
|
|
9
7
|
import { parsedArgs } from "./argv";
|
|
10
|
-
import { blue, redBright, yellow } from "colorette";
|
|
11
8
|
import { getMergedRenderedCookies } from "./getMergedRenderedCookies";
|
|
12
9
|
import { cookieSpecsFromUrl } from "./cookieSpecsFromUrl";
|
|
13
10
|
import CookieSpec from "./CookieSpec";
|
|
@@ -18,7 +15,8 @@ if (typeof fetchImpl !== "function") {
|
|
|
18
15
|
throw new Error("fetch is not a function");
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
const userAgent =
|
|
18
|
+
const userAgent =
|
|
19
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36";
|
|
22
20
|
|
|
23
21
|
interface FetchRequestInit {
|
|
24
22
|
url: RequestInfo | URL | string;
|
|
@@ -29,7 +27,7 @@ export async function fetchWithCookies(
|
|
|
29
27
|
url: RequestInfo | URL | string,
|
|
30
28
|
options: RequestInit | undefined = {},
|
|
31
29
|
fetch: Function = fetchImpl as Function,
|
|
32
|
-
originalRequest: FetchRequestInit | undefined = undefined
|
|
30
|
+
originalRequest: FetchRequestInit | undefined = undefined,
|
|
33
31
|
): Promise<Response> {
|
|
34
32
|
if (typeof fetch !== "function") {
|
|
35
33
|
const message = "fetch is not a function";
|
|
@@ -52,11 +50,11 @@ export async function fetchWithCookies(
|
|
|
52
50
|
(err) => {
|
|
53
51
|
consola.error(err);
|
|
54
52
|
return "";
|
|
55
|
-
}
|
|
53
|
+
},
|
|
56
54
|
);
|
|
57
55
|
if (parsedArgs["dump-request-headers"]) {
|
|
58
|
-
consola.info(
|
|
59
|
-
consola.info(
|
|
56
|
+
consola.info("Request URL:", url1.href);
|
|
57
|
+
consola.info("Request headers:", headers);
|
|
60
58
|
}
|
|
61
59
|
const newOptions1: RequestInit = merge(defaultOptions, { headers }, options);
|
|
62
60
|
try {
|
|
@@ -82,14 +80,14 @@ export async function fetchWithCookies(
|
|
|
82
80
|
// follow the redirect
|
|
83
81
|
if (newUrl && newUrl !== url2) {
|
|
84
82
|
if (parsedArgs.verbose || parsedArgs["dump-response-headers"]) {
|
|
85
|
-
console.log(
|
|
83
|
+
console.log(`Redirected to `, newUrl);
|
|
86
84
|
}
|
|
87
85
|
return fetchWithCookies(
|
|
88
86
|
//
|
|
89
87
|
newUrl,
|
|
90
88
|
newOptions1,
|
|
91
89
|
fetch,
|
|
92
|
-
originalRequest1
|
|
90
|
+
originalRequest1,
|
|
93
91
|
//
|
|
94
92
|
);
|
|
95
93
|
}
|
|
@@ -114,14 +112,14 @@ export async function fetchWithCookies(
|
|
|
114
112
|
break;
|
|
115
113
|
}
|
|
116
114
|
if (parsedArgs.verbose) {
|
|
117
|
-
console.log(
|
|
115
|
+
console.log(`Redirected to `, newUrl);
|
|
118
116
|
}
|
|
119
117
|
return fetchWithCookies(
|
|
120
118
|
//
|
|
121
119
|
newUrl,
|
|
122
120
|
newOptions2,
|
|
123
121
|
fetch,
|
|
124
|
-
originalRequest1
|
|
122
|
+
originalRequest1,
|
|
125
123
|
//
|
|
126
124
|
);
|
|
127
125
|
}
|
|
@@ -146,7 +144,7 @@ export async function fetchWithCookies(
|
|
|
146
144
|
|
|
147
145
|
async function formData(): Promise<FormData> {
|
|
148
146
|
const urlSearchParams: URLSearchParams = await text().then(
|
|
149
|
-
(text) => new URLSearchParams(text)
|
|
147
|
+
(text) => new URLSearchParams(text),
|
|
150
148
|
);
|
|
151
149
|
const formData = new FormData();
|
|
152
150
|
for (const [key, value] of urlSearchParams.entries()) {
|
package/src/findAllFiles.ts
CHANGED
package/src/getChromeCookie.ts
CHANGED
|
@@ -5,11 +5,11 @@ import ChromeCookieQueryStrategy from "./browsers/ChromeCookieQueryStrategy";
|
|
|
5
5
|
import { isExportedCookie } from "./ExportedCookie";
|
|
6
6
|
|
|
7
7
|
export async function getChromeCookie(
|
|
8
|
-
params: CookieSpec
|
|
8
|
+
params: CookieSpec,
|
|
9
9
|
): Promise<ExportedCookie | undefined> {
|
|
10
10
|
const cookies = await queryCookies(
|
|
11
11
|
params,
|
|
12
|
-
new ChromeCookieQueryStrategy()
|
|
12
|
+
new ChromeCookieQueryStrategy(),
|
|
13
13
|
//
|
|
14
14
|
);
|
|
15
15
|
if (cookies.length == 0) {
|
package/src/getCookie.ts
CHANGED
|
@@ -4,12 +4,12 @@ import { queryCookies } from "./queryCookies";
|
|
|
4
4
|
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
5
5
|
|
|
6
6
|
export async function getCookie(
|
|
7
|
-
params: CookieSpec
|
|
7
|
+
params: CookieSpec,
|
|
8
8
|
): Promise<ExportedCookie | undefined> {
|
|
9
9
|
//
|
|
10
10
|
const cookies = await queryCookies(
|
|
11
11
|
params,
|
|
12
|
-
new CompositeCookieQueryStrategy()
|
|
12
|
+
new CompositeCookieQueryStrategy(),
|
|
13
13
|
//
|
|
14
14
|
);
|
|
15
15
|
if (Array.isArray(cookies) && cookies.length > 0) {
|
package/src/getFirefoxCookie.ts
CHANGED
|
@@ -4,11 +4,11 @@ import { queryCookies } from "./queryCookies";
|
|
|
4
4
|
import FirefoxCookieQueryStrategy from "./browsers/FirefoxCookieQueryStrategy";
|
|
5
5
|
|
|
6
6
|
export async function getFirefoxCookie(
|
|
7
|
-
params: CookieSpec
|
|
7
|
+
params: CookieSpec,
|
|
8
8
|
): Promise<ExportedCookie | undefined> {
|
|
9
9
|
const cookies: ExportedCookie[] = await queryCookies(
|
|
10
10
|
params,
|
|
11
|
-
new FirefoxCookieQueryStrategy()
|
|
11
|
+
new FirefoxCookieQueryStrategy(),
|
|
12
12
|
//
|
|
13
13
|
);
|
|
14
14
|
if (Array.isArray(cookies) && cookies.length > 0) {
|
|
@@ -5,7 +5,7 @@ import ExportedCookie from "./ExportedCookie";
|
|
|
5
5
|
import { comboQueryCookieSpec } from "./comboQueryCookieSpec";
|
|
6
6
|
|
|
7
7
|
export async function getGroupedRenderedCookies(
|
|
8
|
-
cookieSpec: MultiCookieSpec
|
|
8
|
+
cookieSpec: MultiCookieSpec,
|
|
9
9
|
): Promise<string[]> {
|
|
10
10
|
const cookies: ExportedCookie[] = await comboQueryCookieSpec(cookieSpec);
|
|
11
11
|
if (cookies.length == 0) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getMergedRenderedCookies } from "./getMergedRenderedCookies";
|
|
2
|
+
import { MultiCookieSpec } from "./CookieSpec";
|
|
3
|
+
|
|
4
|
+
describe("getMergedRenderedCookies", () => {
|
|
5
|
+
it("should return empty string if no cookies are present", async () => {
|
|
6
|
+
const cookieSpec: MultiCookieSpec = [];
|
|
7
|
+
const result = await getMergedRenderedCookies(cookieSpec);
|
|
8
|
+
expect(result).toBe("");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should return rendered cookies if cookies are present", async () => {
|
|
12
|
+
const cookieSpec: MultiCookieSpec = [
|
|
13
|
+
{
|
|
14
|
+
name: "sessionCookie",
|
|
15
|
+
domain: "www.example.com",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "persistentCookie",
|
|
19
|
+
domain: "www.example.com",
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
const result = await getMergedRenderedCookies(cookieSpec);
|
|
23
|
+
expect(result).not.toBe("");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -5,7 +5,7 @@ import ExportedCookie from "./ExportedCookie";
|
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
|
|
7
7
|
export async function getMergedRenderedCookies(
|
|
8
|
-
cookieSpec: MultiCookieSpec
|
|
8
|
+
cookieSpec: MultiCookieSpec,
|
|
9
9
|
): Promise<string> {
|
|
10
10
|
const cookies: ExportedCookie[] = await comboQueryCookieSpec(cookieSpec);
|
|
11
11
|
return cookies.length > 0 ? resultsRendered(cookies) : "";
|
package/src/queryCookies.ts
CHANGED
|
@@ -10,9 +10,12 @@ export async function queryCookies(
|
|
|
10
10
|
{
|
|
11
11
|
name,
|
|
12
12
|
domain,
|
|
13
|
+
limit,
|
|
13
14
|
}: //
|
|
14
|
-
CookieSpec
|
|
15
|
-
|
|
15
|
+
CookieSpec & {
|
|
16
|
+
limit?: number;
|
|
17
|
+
},
|
|
18
|
+
strategy: CookieQueryStrategy = new CompositeCookieQueryStrategy(),
|
|
16
19
|
): Promise<ExportedCookie[]> {
|
|
17
20
|
//
|
|
18
21
|
const results: ExportedCookie[] = await strategy.queryCookies(name, domain);
|
package/src/util/flatMapAsync.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export async function flatMapAsync<T, O>(
|
|
5
5
|
array: T[], // The input array to transform.
|
|
6
6
|
callback: (value: T, index: number, array: T[]) => Promise<O[]>, // The async function to apply to each input array element.,
|
|
7
|
-
or?: O[] | ((error: any) => O[] | Promise<O[]>) // An optional callback to handle errors.
|
|
7
|
+
or?: O[] | ((error: any) => O[] | Promise<O[]>), // An optional callback to handle errors.
|
|
8
8
|
): Promise<O[]> {
|
|
9
9
|
if (or) {
|
|
10
10
|
return flatMapAsync(
|
|
@@ -15,7 +15,7 @@ export async function flatMapAsync<T, O>(
|
|
|
15
15
|
} catch (error) {
|
|
16
16
|
return typeof or == "function" ? or(error) : or;
|
|
17
17
|
}
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
19
|
//
|
|
20
20
|
);
|
|
21
21
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
"include": [
|
|
2
|
+
"include": [
|
|
3
|
+
"src/**.ts",
|
|
4
|
+
"src/**.tsx",
|
|
5
|
+
"src/**.js",
|
|
6
|
+
"src/**.jsx",
|
|
7
|
+
"src/**.test.ts",
|
|
8
|
+
"src/**.test.js"
|
|
9
|
+
],
|
|
3
10
|
"compilerOptions": {
|
|
4
11
|
"moduleResolution": "node",
|
|
5
12
|
"target": "es6",
|
|
6
|
-
"types": ["node"],
|
|
13
|
+
"types": ["node", "jest"],
|
|
7
14
|
"lib": ["es2015", "es2017", "es2021", "dom"],
|
|
8
15
|
"strict": true,
|
|
9
16
|
"skipDefaultLibCheck": true,
|