@mherod/get-cookie 2.0.0-rc.14 → 2.0.0-rc.16
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 +26 -9
- package/package-lock.json +34 -31
- package/package.json +6 -6
- package/src/fetchWithCookies.ts +36 -11
package/dist/index.js
CHANGED
|
@@ -789,7 +789,8 @@ function $2d84054eb5f070a6$export$f266452a5050185d(url) {
|
|
|
789
789
|
|
|
790
790
|
|
|
791
791
|
const $cfc07ae4aa2c7e44$var$userAgent = new (0, ($parcel$interopDefault($7oI3p$useragents)))().toString();
|
|
792
|
-
async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetch = (0, $7oI3p$crossfetch.fetch)) {
|
|
792
|
+
async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetch = (0, $7oI3p$crossfetch.fetch), originalRequest) {
|
|
793
|
+
const originalRequest1 = originalRequest || new Request(url, options);
|
|
793
794
|
const headers = {
|
|
794
795
|
"User-Agent": $cfc07ae4aa2c7e44$var$userAgent
|
|
795
796
|
};
|
|
@@ -816,20 +817,36 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
|
|
|
816
817
|
});
|
|
817
818
|
for (const [key, value] of headers1)if (key === "set-cookie") {
|
|
818
819
|
await (0, $53a3bcc99a05dfcf$export$928a906645f9d018).setCookie(value, url2);
|
|
819
|
-
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Set-Cookie
|
|
820
|
-
// const cookie = tough.parse(value);
|
|
821
|
-
// if (cookie instanceof Cookie) {
|
|
822
|
-
// await memoryCookieStore.putCookie(cookie);
|
|
823
|
-
// }
|
|
820
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Set-Cookie:`), (0, $7oI3p$colorette.yellow)(value), (0, $7oI3p$colorette.yellow)(url2));
|
|
824
821
|
}
|
|
825
|
-
const newUrl = res.headers.get("location");
|
|
826
|
-
|
|
822
|
+
const newUrl = res.headers.get("location") ?? res.url;
|
|
823
|
+
const sameHost = new URL(newUrl).host === url1.host;
|
|
824
|
+
if (res.status == 301 || res.status == 302) // follow the redirect
|
|
827
825
|
{
|
|
828
826
|
if (newUrl && newUrl !== url2) {
|
|
829
827
|
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Redirected to `), (0, $7oI3p$colorette.yellow)(newUrl));
|
|
830
828
|
return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(//
|
|
831
|
-
newUrl, newOptions1, fetch);
|
|
829
|
+
newUrl, newOptions1, fetch, originalRequest1);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (res.status == 303 && newUrl && newUrl !== url2) {
|
|
833
|
+
// follow the redirect with GET
|
|
834
|
+
let newOptions2 = {};
|
|
835
|
+
switch(newOptions1.method){
|
|
836
|
+
case "POST":
|
|
837
|
+
case "PUT":
|
|
838
|
+
case "DELETE":
|
|
839
|
+
(0, $7oI3p$lodash.merge)(newOptions2, newOptions1, {
|
|
840
|
+
method: "GET"
|
|
841
|
+
});
|
|
842
|
+
break;
|
|
843
|
+
default:
|
|
844
|
+
(0, $7oI3p$lodash.merge)(newOptions2, newOptions1);
|
|
845
|
+
break;
|
|
832
846
|
}
|
|
847
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Redirected to `), (0, $7oI3p$colorette.yellow)(newUrl));
|
|
848
|
+
return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(//
|
|
849
|
+
newUrl, newOptions2, fetch, originalRequest1);
|
|
833
850
|
}
|
|
834
851
|
const arrayBuffer1 = res.arrayBuffer();
|
|
835
852
|
async function arrayBuffer() {
|
package/package-lock.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mherod/get-cookie",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.14",
|
|
4
4
|
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@mherod/get-cookie",
|
|
9
|
-
"version": "2.0.0-rc.
|
|
9
|
+
"version": "2.0.0-rc.14",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"colorette": "^2.0.19",
|
|
13
13
|
"cross-fetch": "^3.1.5",
|
|
14
|
-
"destr": "^1.
|
|
14
|
+
"destr": "^1.2.0",
|
|
15
15
|
"jsonwebtoken": "^8.5.1",
|
|
16
16
|
"lodash": "^4.17.21",
|
|
17
17
|
"lru-cache": "^7.14.0",
|
|
18
|
-
"minimist": "^1.2.
|
|
19
|
-
"sqlite3": "^5.1.
|
|
18
|
+
"minimist": "^1.2.7",
|
|
19
|
+
"sqlite3": "^5.1.2",
|
|
20
20
|
"tough-cookie": "^4.1.2",
|
|
21
21
|
"tough-cookie-file-store": "^2.0.3",
|
|
22
|
-
"user-agents": "^1.0.
|
|
22
|
+
"user-agents": "^1.0.1178"
|
|
23
23
|
},
|
|
24
24
|
"bin": {
|
|
25
25
|
"get-cookie": "dist/cli.js"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@types/jsonwebtoken": "^8.5.9",
|
|
31
31
|
"@types/lodash": "^4.14.186",
|
|
32
32
|
"@types/minimist": "^1.2.2",
|
|
33
|
-
"@types/node": "^18.
|
|
33
|
+
"@types/node": "^18.11.4",
|
|
34
34
|
"@types/tough-cookie": "^4.0.2",
|
|
35
35
|
"@types/user-agents": "^1.0.2",
|
|
36
36
|
"parcel": "^2.7.0",
|
|
@@ -1837,9 +1837,9 @@
|
|
|
1837
1837
|
"dev": true
|
|
1838
1838
|
},
|
|
1839
1839
|
"node_modules/@types/node": {
|
|
1840
|
-
"version": "18.
|
|
1841
|
-
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.
|
|
1842
|
-
"integrity": "sha512-
|
|
1840
|
+
"version": "18.11.4",
|
|
1841
|
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.4.tgz",
|
|
1842
|
+
"integrity": "sha512-BxcJpBu8D3kv/GZkx/gSMz6VnTJREBj/4lbzYOQueUOELkt8WrO6zAcSPmp9uRPEW/d+lUO8QK0W2xnS1hEU0A==",
|
|
1843
1843
|
"dev": true
|
|
1844
1844
|
},
|
|
1845
1845
|
"node_modules/@types/parse-json": {
|
|
@@ -2325,9 +2325,9 @@
|
|
|
2325
2325
|
}
|
|
2326
2326
|
},
|
|
2327
2327
|
"node_modules/destr": {
|
|
2328
|
-
"version": "1.
|
|
2329
|
-
"resolved": "https://registry.npmjs.org/destr/-/destr-1.
|
|
2330
|
-
"integrity": "sha512-
|
|
2328
|
+
"version": "1.2.0",
|
|
2329
|
+
"resolved": "https://registry.npmjs.org/destr/-/destr-1.2.0.tgz",
|
|
2330
|
+
"integrity": "sha512-JG+cG4ZPB1L27sl2C2URg8MIOmIUtTbE5wEx02BpmrTCqg/hXxFKXsYsnODl5PdpqNRaS1KQGUQ56V8jk8XpYQ=="
|
|
2331
2331
|
},
|
|
2332
2332
|
"node_modules/detect-indent": {
|
|
2333
2333
|
"version": "6.0.0",
|
|
@@ -3266,9 +3266,12 @@
|
|
|
3266
3266
|
}
|
|
3267
3267
|
},
|
|
3268
3268
|
"node_modules/minimist": {
|
|
3269
|
-
"version": "1.2.
|
|
3270
|
-
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.
|
|
3271
|
-
"integrity": "sha512-
|
|
3269
|
+
"version": "1.2.7",
|
|
3270
|
+
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
|
|
3271
|
+
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==",
|
|
3272
|
+
"funding": {
|
|
3273
|
+
"url": "https://github.com/sponsors/ljharb"
|
|
3274
|
+
}
|
|
3272
3275
|
},
|
|
3273
3276
|
"node_modules/minipass": {
|
|
3274
3277
|
"version": "3.1.6",
|
|
@@ -4319,9 +4322,9 @@
|
|
|
4319
4322
|
}
|
|
4320
4323
|
},
|
|
4321
4324
|
"node_modules/user-agents": {
|
|
4322
|
-
"version": "1.0.
|
|
4323
|
-
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.
|
|
4324
|
-
"integrity": "sha512
|
|
4325
|
+
"version": "1.0.1178",
|
|
4326
|
+
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.1178.tgz",
|
|
4327
|
+
"integrity": "sha512-xcE6igv9dKy3ZrGwHr6ga1eDXyr0ln+BF/OhtoLxm86CHk1APqxo9HqvLYYNS3s80XwuVdl7vdEhMXCTXXCPpw==",
|
|
4325
4328
|
"dependencies": {
|
|
4326
4329
|
"dot-json": "^1.2.2",
|
|
4327
4330
|
"lodash.clonedeep": "^4.5.0"
|
|
@@ -5643,9 +5646,9 @@
|
|
|
5643
5646
|
"dev": true
|
|
5644
5647
|
},
|
|
5645
5648
|
"@types/node": {
|
|
5646
|
-
"version": "18.
|
|
5647
|
-
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.
|
|
5648
|
-
"integrity": "sha512-
|
|
5649
|
+
"version": "18.11.4",
|
|
5650
|
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.4.tgz",
|
|
5651
|
+
"integrity": "sha512-BxcJpBu8D3kv/GZkx/gSMz6VnTJREBj/4lbzYOQueUOELkt8WrO6zAcSPmp9uRPEW/d+lUO8QK0W2xnS1hEU0A==",
|
|
5649
5652
|
"dev": true
|
|
5650
5653
|
},
|
|
5651
5654
|
"@types/parse-json": {
|
|
@@ -6012,9 +6015,9 @@
|
|
|
6012
6015
|
"optional": true
|
|
6013
6016
|
},
|
|
6014
6017
|
"destr": {
|
|
6015
|
-
"version": "1.
|
|
6016
|
-
"resolved": "https://registry.npmjs.org/destr/-/destr-1.
|
|
6017
|
-
"integrity": "sha512-
|
|
6018
|
+
"version": "1.2.0",
|
|
6019
|
+
"resolved": "https://registry.npmjs.org/destr/-/destr-1.2.0.tgz",
|
|
6020
|
+
"integrity": "sha512-JG+cG4ZPB1L27sl2C2URg8MIOmIUtTbE5wEx02BpmrTCqg/hXxFKXsYsnODl5PdpqNRaS1KQGUQ56V8jk8XpYQ=="
|
|
6018
6021
|
},
|
|
6019
6022
|
"detect-indent": {
|
|
6020
6023
|
"version": "6.0.0",
|
|
@@ -6670,9 +6673,9 @@
|
|
|
6670
6673
|
}
|
|
6671
6674
|
},
|
|
6672
6675
|
"minimist": {
|
|
6673
|
-
"version": "1.2.
|
|
6674
|
-
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.
|
|
6675
|
-
"integrity": "sha512-
|
|
6676
|
+
"version": "1.2.7",
|
|
6677
|
+
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
|
|
6678
|
+
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g=="
|
|
6676
6679
|
},
|
|
6677
6680
|
"minipass": {
|
|
6678
6681
|
"version": "3.1.6",
|
|
@@ -7436,9 +7439,9 @@
|
|
|
7436
7439
|
}
|
|
7437
7440
|
},
|
|
7438
7441
|
"user-agents": {
|
|
7439
|
-
"version": "1.0.
|
|
7440
|
-
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.
|
|
7441
|
-
"integrity": "sha512
|
|
7442
|
+
"version": "1.0.1178",
|
|
7443
|
+
"resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.1178.tgz",
|
|
7444
|
+
"integrity": "sha512-xcE6igv9dKy3ZrGwHr6ga1eDXyr0ln+BF/OhtoLxm86CHk1APqxo9HqvLYYNS3s80XwuVdl7vdEhMXCTXXCPpw==",
|
|
7442
7445
|
"requires": {
|
|
7443
7446
|
"dot-json": "^1.2.2",
|
|
7444
7447
|
"lodash.clonedeep": "^4.5.0"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mherod/get-cookie",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.16",
|
|
4
4
|
"description": "Node.js module for querying a local user's Chrome cookie",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"bin": "dist/cli.js",
|
|
@@ -59,15 +59,15 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"colorette": "^2.0.19",
|
|
61
61
|
"cross-fetch": "^3.1.5",
|
|
62
|
-
"destr": "^1.
|
|
62
|
+
"destr": "^1.2.0",
|
|
63
63
|
"jsonwebtoken": "^8.5.1",
|
|
64
64
|
"lodash": "^4.17.21",
|
|
65
65
|
"lru-cache": "^7.14.0",
|
|
66
|
-
"minimist": "^1.2.
|
|
67
|
-
"sqlite3": "^5.1.
|
|
66
|
+
"minimist": "^1.2.7",
|
|
67
|
+
"sqlite3": "^5.1.2",
|
|
68
68
|
"tough-cookie": "^4.1.2",
|
|
69
69
|
"tough-cookie-file-store": "^2.0.3",
|
|
70
|
-
"user-agents": "^1.0.
|
|
70
|
+
"user-agents": "^1.0.1178"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@parcel/packager-ts": "^2.7.0",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@types/jsonwebtoken": "^8.5.9",
|
|
76
76
|
"@types/lodash": "^4.14.186",
|
|
77
77
|
"@types/minimist": "^1.2.2",
|
|
78
|
-
"@types/node": "^18.
|
|
78
|
+
"@types/node": "^18.11.4",
|
|
79
79
|
"@types/tough-cookie": "^4.0.2",
|
|
80
80
|
"@types/user-agents": "^1.0.2",
|
|
81
81
|
"parcel": "^2.7.0",
|
package/src/fetchWithCookies.ts
CHANGED
|
@@ -17,8 +17,10 @@ const userAgent = new UserAgent().toString();
|
|
|
17
17
|
export async function fetchWithCookies(
|
|
18
18
|
url: RequestInfo | URL,
|
|
19
19
|
options: RequestInit | undefined = {},
|
|
20
|
-
fetch: Function = fetchImpl
|
|
20
|
+
fetch: Function = fetchImpl,
|
|
21
|
+
originalRequest: Request | undefined = undefined
|
|
21
22
|
): Promise<Response> {
|
|
23
|
+
const originalRequest1 = originalRequest || new Request(url, options);
|
|
22
24
|
const headers: HeadersInit = {
|
|
23
25
|
"User-Agent": userAgent,
|
|
24
26
|
};
|
|
@@ -46,18 +48,15 @@ export async function fetchWithCookies(
|
|
|
46
48
|
if (key === "set-cookie") {
|
|
47
49
|
await cookieJar.setCookie(value, url2);
|
|
48
50
|
if (parsedArgs.verbose) {
|
|
49
|
-
console.log(blue(`Set-Cookie
|
|
51
|
+
console.log(blue(`Set-Cookie:`), yellow(value), yellow(url2));
|
|
50
52
|
}
|
|
51
|
-
// const cookie = tough.parse(value);
|
|
52
|
-
// if (cookie instanceof Cookie) {
|
|
53
|
-
// await memoryCookieStore.putCookie(cookie);
|
|
54
|
-
// }
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
const newUrl: string = res.headers.get("location")
|
|
56
|
+
const newUrl: string = res.headers.get("location") ?? res.url;
|
|
57
|
+
const sameHost = new URL(newUrl).host === url1.host;
|
|
59
58
|
if (res.status == 301 || res.status == 302) {
|
|
60
|
-
//
|
|
59
|
+
// follow the redirect
|
|
61
60
|
if (newUrl && newUrl !== url2) {
|
|
62
61
|
if (parsedArgs.verbose) {
|
|
63
62
|
console.log(blue(`Redirected to `), yellow(newUrl));
|
|
@@ -66,11 +65,37 @@ export async function fetchWithCookies(
|
|
|
66
65
|
//
|
|
67
66
|
newUrl,
|
|
68
67
|
newOptions1,
|
|
69
|
-
fetch
|
|
68
|
+
fetch,
|
|
69
|
+
originalRequest1
|
|
70
70
|
//
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
if (res.status == 303 && newUrl && newUrl !== url2) {
|
|
75
|
+
// follow the redirect with GET
|
|
76
|
+
let newOptions2: RequestInit = {};
|
|
77
|
+
switch (newOptions1.method) {
|
|
78
|
+
case "POST":
|
|
79
|
+
case "PUT":
|
|
80
|
+
case "DELETE":
|
|
81
|
+
merge(newOptions2, newOptions1, { method: "GET" });
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
merge(newOptions2, newOptions1);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (parsedArgs.verbose) {
|
|
88
|
+
console.log(blue(`Redirected to `), yellow(newUrl));
|
|
89
|
+
}
|
|
90
|
+
return fetchWithCookies(
|
|
91
|
+
//
|
|
92
|
+
newUrl,
|
|
93
|
+
newOptions2,
|
|
94
|
+
fetch,
|
|
95
|
+
originalRequest1
|
|
96
|
+
//
|
|
97
|
+
);
|
|
98
|
+
}
|
|
74
99
|
|
|
75
100
|
const arrayBuffer1: Promise<ArrayBuffer> = res.arrayBuffer();
|
|
76
101
|
|
|
@@ -83,11 +108,11 @@ export async function fetchWithCookies(
|
|
|
83
108
|
}
|
|
84
109
|
|
|
85
110
|
async function text(): Promise<string> {
|
|
86
|
-
return buffer().then((buffer) => buffer.toString("utf8"));
|
|
111
|
+
return buffer().then((buffer: Buffer) => buffer.toString("utf8"));
|
|
87
112
|
}
|
|
88
113
|
|
|
89
114
|
async function json(): Promise<any> {
|
|
90
|
-
return text().then((text) => destr(text));
|
|
115
|
+
return text().then((text: string) => destr(text));
|
|
91
116
|
}
|
|
92
117
|
|
|
93
118
|
async function formData(): Promise<FormData> {
|