@mherod/get-cookie 2.0.0-rc.8 → 2.0.0-rc.9
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 +31 -8
- package/package.json +1 -1
- package/src/fetchWithCookies.ts +12 -9
- package/src/getMergedRenderedCookies.ts +25 -0
- package/src/index.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -41,6 +41,7 @@ function $parcel$interopDefault(a) {
|
|
|
41
41
|
$parcel$export(module.exports, "getCookie", () => $8481e2034946cc4b$export$4be65e66cfa2648a);
|
|
42
42
|
$parcel$export(module.exports, "getChromeCookie", () => $1a92ef2038b55530$export$e5637297e9eb6f2e);
|
|
43
43
|
$parcel$export(module.exports, "getFirefoxCookie", () => $f9b70200901ad17d$export$c44c5fdef43f0941);
|
|
44
|
+
$parcel$export(module.exports, "getMergedRenderedCookies", () => $4ffeaeb7bb3c0319$export$cfc0723de5712e57);
|
|
44
45
|
$parcel$export(module.exports, "getGroupedRenderedCookies", () => $300d8b33187a203c$export$4d2e9997e2c23417);
|
|
45
46
|
$parcel$export(module.exports, "fetchWithCookies", () => $cfc07ae4aa2c7e44$export$b24a545a0b39f491);
|
|
46
47
|
|
|
@@ -722,6 +723,23 @@ async function $300d8b33187a203c$export$4d2e9997e2c23417({ name: name , domain:
|
|
|
722
723
|
|
|
723
724
|
|
|
724
725
|
|
|
726
|
+
async function $4ffeaeb7bb3c0319$export$cfc0723de5712e57({ name: name , domain: domain }) {
|
|
727
|
+
const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)({
|
|
728
|
+
name: name,
|
|
729
|
+
domain: domain
|
|
730
|
+
}, new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)());
|
|
731
|
+
if (cookies.length == 0) throw new Error("Cookie not found");
|
|
732
|
+
const results = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)({
|
|
733
|
+
name: name,
|
|
734
|
+
domain: domain
|
|
735
|
+
});
|
|
736
|
+
return (0, $9c43c2ed82e63570$export$9abc0a414b0d8b8f)(results);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
725
743
|
|
|
726
744
|
|
|
727
745
|
|
|
@@ -743,23 +761,28 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
|
|
|
743
761
|
name: "%",
|
|
744
762
|
domain: domain
|
|
745
763
|
};
|
|
746
|
-
const cookies = await (
|
|
747
|
-
|
|
764
|
+
// const cookies: string[] = await getGroupedRenderedCookies(cookieSpec).catch(
|
|
765
|
+
// () => []
|
|
766
|
+
// );
|
|
767
|
+
// const cookie = cookies.pop();
|
|
768
|
+
const cookie = await (0, $4ffeaeb7bb3c0319$export$cfc0723de5712e57)(cookieSpec).catch(()=>"");
|
|
769
|
+
const headers = {};
|
|
770
|
+
if (cookie.length > 0) (0, $7oI3p$lodash.merge)(headers, {
|
|
771
|
+
Cookie: cookie
|
|
772
|
+
});
|
|
748
773
|
const newOptions1 = (0, $7oI3p$lodash.merge)(defaultOptions, options, {
|
|
749
|
-
headers:
|
|
750
|
-
Cookie: cookie
|
|
751
|
-
}
|
|
774
|
+
headers: headers
|
|
752
775
|
});
|
|
753
776
|
try {
|
|
754
777
|
const res = await fetch(url2, newOptions1);
|
|
755
|
-
const
|
|
778
|
+
const headers1 = [];
|
|
756
779
|
res.headers.forEach((value, key)=>{
|
|
757
|
-
|
|
780
|
+
headers1.push([
|
|
758
781
|
key,
|
|
759
782
|
value
|
|
760
783
|
]);
|
|
761
784
|
});
|
|
762
|
-
for (const [key, value] of
|
|
785
|
+
for (const [key, value] of headers1)if (key === "set-cookie") {
|
|
763
786
|
await (0, $53a3bcc99a05dfcf$export$928a906645f9d018).setCookie(value, url2);
|
|
764
787
|
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Set-Cookie: ${(0, $7oI3p$colorette.yellow)(value)} ${(0, $7oI3p$colorette.yellow)(url2)}`));
|
|
765
788
|
// const cookie = tough.parse(value);
|
package/package.json
CHANGED
package/src/fetchWithCookies.ts
CHANGED
|
@@ -5,11 +5,11 @@ import { merge } from "lodash";
|
|
|
5
5
|
// noinspection SpellCheckingInspection
|
|
6
6
|
import destr from "destr";
|
|
7
7
|
import CookieSpec from "./CookieSpec";
|
|
8
|
-
import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
|
|
9
8
|
import { cookieJar } from "./CookieStore";
|
|
10
9
|
import UserAgent from "user-agents";
|
|
11
10
|
import { parsedArgs } from "./argv";
|
|
12
11
|
import { blue, yellow } from "colorette";
|
|
12
|
+
import { getMergedRenderedCookies } from "./getMergedRenderedCookies";
|
|
13
13
|
|
|
14
14
|
export async function fetchWithCookies(
|
|
15
15
|
url: RequestInfo | URL,
|
|
@@ -31,15 +31,18 @@ export async function fetchWithCookies(
|
|
|
31
31
|
name: "%",
|
|
32
32
|
domain: domain,
|
|
33
33
|
};
|
|
34
|
-
const cookies: string[] = await getGroupedRenderedCookies(cookieSpec).catch(
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
const cookie = cookies.pop();
|
|
38
|
-
const
|
|
39
|
-
|
|
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, {
|
|
40
42
|
Cookie: cookie,
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const newOptions1: RequestInit = merge(defaultOptions, options, { headers });
|
|
43
46
|
try {
|
|
44
47
|
const res: Response = await fetch(url2, newOptions1);
|
|
45
48
|
const headers: [string, string][] = [];
|
|
@@ -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
|
@@ -5,12 +5,14 @@ import { getCookie } from "./getCookie";
|
|
|
5
5
|
import { getChromeCookie } from "./getChromeCookie";
|
|
6
6
|
import { getFirefoxCookie } from "./getFirefoxCookie";
|
|
7
7
|
import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
|
|
8
|
+
import { getMergedRenderedCookies } from "./getMergedRenderedCookies";
|
|
8
9
|
import { fetchWithCookies } from "./fetchWithCookies";
|
|
9
10
|
|
|
10
11
|
export {
|
|
11
12
|
getCookie,
|
|
12
13
|
getChromeCookie,
|
|
13
14
|
getFirefoxCookie,
|
|
15
|
+
getMergedRenderedCookies,
|
|
14
16
|
getGroupedRenderedCookies,
|
|
15
17
|
fetchWithCookies,
|
|
16
18
|
//
|