@mherod/get-cookie 2.0.0-rc.13 → 2.0.0-rc.14

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 CHANGED
@@ -800,16 +800,13 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
800
800
  const url2 = `${url}`;
801
801
  const url1 = new URL(url2);
802
802
  const cookieSpecs = (0, $2d84054eb5f070a6$export$f266452a5050185d)(url1);
803
- const cookie = await (0, $4ffeaeb7bb3c0319$export$cfc0723de5712e57)(cookieSpecs).catch(()=>"");
804
- if (cookie.length > 0) (0, $7oI3p$lodash.merge)(headers, {
805
- Cookie: cookie
806
- });
803
+ headers["Cookie"] = await (0, $4ffeaeb7bb3c0319$export$cfc0723de5712e57)(cookieSpecs).catch(()=>"");
807
804
  if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b)["dump-request-headers"]) console.log((0, $7oI3p$colorette.blue)("Request headers:"), headers);
808
- const newOptions1 = (0, $7oI3p$lodash.merge)(defaultOptions, options, {
805
+ const newOptions1 = (0, $7oI3p$lodash.merge)(defaultOptions, {
809
806
  headers: headers
810
- });
807
+ }, options);
811
808
  try {
812
- const res = await fetch(url2, newOptions1);
809
+ const res = await fetch(url1, newOptions1);
813
810
  const headers1 = [];
814
811
  res.headers.forEach((value, key)=>{
815
812
  headers1.push([
@@ -826,12 +823,13 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
826
823
  // }
827
824
  }
828
825
  const newUrl = res.headers.get("location");
829
- if (res.status >= 300 && res.status < 400) {
826
+ if (res.status == 301 || res.status == 302) // const sameHost = new URL(newUrl).host === url1.host;
827
+ {
830
828
  if (newUrl && newUrl !== url2) {
831
829
  if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Redirected to `), (0, $7oI3p$colorette.yellow)(newUrl));
832
830
  return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(//
833
831
  newUrl, newOptions1, fetch);
834
- } else throw new Error("Redirected but no new location");
832
+ }
835
833
  }
836
834
  const arrayBuffer1 = res.arrayBuffer();
837
835
  async function arrayBuffer() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mherod/get-cookie",
3
- "version": "2.0.0-rc.13",
3
+ "version": "2.0.0-rc.14",
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",
@@ -19,7 +19,7 @@ export async function fetchWithCookies(
19
19
  options: RequestInit | undefined = {},
20
20
  fetch: Function = fetchImpl
21
21
  ): Promise<Response> {
22
- const headers = {
22
+ const headers: HeadersInit = {
23
23
  "User-Agent": userAgent,
24
24
  };
25
25
  const defaultOptions: RequestInit = {
@@ -29,18 +29,15 @@ export async function fetchWithCookies(
29
29
  const url2: string = `${url}`;
30
30
  const url1: URL = new URL(url2);
31
31
  const cookieSpecs: CookieSpec[] = cookieSpecsFromUrl(url1);
32
- const cookie = await getMergedRenderedCookies(cookieSpecs).catch(() => "");
33
- if (cookie.length > 0) {
34
- merge(headers, {
35
- Cookie: cookie,
36
- });
37
- }
32
+ headers["Cookie"] = await getMergedRenderedCookies(cookieSpecs).catch(
33
+ () => ""
34
+ );
38
35
  if (parsedArgs["dump-request-headers"]) {
39
36
  console.log(blue("Request headers:"), headers);
40
37
  }
41
- const newOptions1: RequestInit = merge(defaultOptions, options, { headers });
38
+ const newOptions1: RequestInit = merge(defaultOptions, { headers }, options);
42
39
  try {
43
- const res: Response = await fetch(url2, newOptions1);
40
+ const res: Response = await fetch(url1, newOptions1);
44
41
  const headers: [string, string][] = [];
45
42
  res.headers.forEach((value, key) => {
46
43
  headers.push([key, value]);
@@ -59,7 +56,8 @@ export async function fetchWithCookies(
59
56
  }
60
57
 
61
58
  const newUrl: string = res.headers.get("location") as string;
62
- if (res.status >= 300 && res.status < 400) {
59
+ if (res.status == 301 || res.status == 302) {
60
+ // const sameHost = new URL(newUrl).host === url1.host;
63
61
  if (newUrl && newUrl !== url2) {
64
62
  if (parsedArgs.verbose) {
65
63
  console.log(blue(`Redirected to `), yellow(newUrl));
@@ -71,8 +69,6 @@ export async function fetchWithCookies(
71
69
  fetch
72
70
  //
73
71
  );
74
- } else {
75
- throw new Error("Redirected but no new location");
76
72
  }
77
73
  }
78
74