@mherod/get-cookie 2.0.0-beta.7 → 2.0.0-beta.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.
@@ -5,7 +5,7 @@ import { toStringOrNull } from "../utils";
5
5
  import { findAllFiles } from "../findAllFiles";
6
6
  import * as path from "path";
7
7
  import { doSqliteQuery1 } from "../doSqliteQuery1";
8
- import ExportedCookie from "../ExportedCookie";
8
+ import { ExportedCookie } from "../ExportedCookie";
9
9
 
10
10
  export default class FirefoxCookieQueryStrategy implements CookieQueryStrategy {
11
11
  async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
@@ -1,5 +1,5 @@
1
1
  import CookieQueryStrategy from "./CookieQueryStrategy";
2
- import ExportedCookie from "../ExportedCookie";
2
+ import { ExportedCookie } from "../ExportedCookie";
3
3
 
4
4
  export default class SafariCookieQueryStrategy implements CookieQueryStrategy {
5
5
  async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
package/src/cli.ts CHANGED
@@ -5,8 +5,8 @@ import { queryCookies } from "./queryCookies";
5
5
  import { argv } from "./argv";
6
6
  import { groupBy } from "lodash";
7
7
  import { blue, green } from "colorette";
8
- import ExportedCookie from "./ExportedCookie";
9
8
  import { resultsRendered } from "./resultsRendered";
9
+ import { ExportedCookie } from "./ExportedCookie";
10
10
 
11
11
  function combinedString(results: ExportedCookie[]) {
12
12
  return blue(resultsRendered(results));
@@ -1,6 +1,6 @@
1
1
  import * as fs from "fs";
2
2
  import * as sqlite3 from "sqlite3";
3
- import CookieRow from "./CookieRow";
3
+ import { CookieRow } from "./CookieRow";
4
4
 
5
5
  export async function doSqliteQuery1(file: string, sql: string): Promise<CookieRow[]> {
6
6
  if (!fs.existsSync(file)) {
@@ -11,19 +11,33 @@ export async function fetchWithCookies(
11
11
  url: RequestInfo | URL,
12
12
  options: RequestInit | undefined = {}
13
13
  ): Promise<FetchResponse> {
14
- const url1 = new URL(`${url}`);
15
- const cookie: string[] = await getGroupedRenderedCookies({
14
+ const defaultOptions: RequestInit = {
15
+ headers: {
16
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
17
+ },
18
+ redirect: "manual"
19
+ };
20
+ const url2: string = `${url}`;
21
+ const url1: URL = new URL(url2);
22
+ const domain = url1.hostname.replace(/^.*(\.\w+\.\w+)$/, (match, p1) => {
23
+ return `%${p1}`;
24
+ });
25
+ const cookies: string[] = await getGroupedRenderedCookies({
16
26
  name: "%",
17
- domain: url1.hostname
27
+ domain: domain
18
28
  });
19
- merge(options, {
20
- credentials: "include",
29
+ const cookie = cookies.pop();
30
+ const newOptions1: RequestInit = merge(defaultOptions, options, {
21
31
  headers: {
22
- Cookie: cookie.pop()
32
+ Cookie: cookie
23
33
  }
24
34
  });
25
35
  try {
26
- const res = await fetch(url, options);
36
+ const res = await fetch(url2, newOptions1);
37
+ const newUrl = res.headers.get("location") as string;
38
+ if (res.redirected || newUrl && newUrl !== url2) {
39
+ return fetchWithCookies(newUrl, newOptions1);
40
+ }
27
41
  const arrayBuffer1 = res.arrayBuffer();
28
42
  const arrayBuffer = async () => arrayBuffer1;
29
43
  const buffer = async () => arrayBuffer().then(Buffer.from);
@@ -1,9 +1,9 @@
1
- import ExportedCookie from "./ExportedCookie";
2
1
  import { queryCookies } from "./queryCookies";
3
2
  import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
4
3
  import { groupBy } from "lodash";
5
4
  import { resultsRendered } from "./resultsRendered";
6
- import CookieRequest from "./CookieRequest";
5
+ import { CookieRequest } from "./CookieRequest";
6
+ import { ExportedCookie } from "./ExportedCookie";
7
7
 
8
8
  export async function getGroupedRenderedCookies(
9
9
  //
package/src/index.ts CHANGED
@@ -5,10 +5,12 @@ import { queryCookies } from "./queryCookies";
5
5
  import FirefoxCookieQueryStrategy from "./browsers/FirefoxCookieQueryStrategy";
6
6
  import ChromeCookieQueryStrategy from "./browsers/ChromeCookieQueryStrategy";
7
7
  import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
8
+ import { CookieRequest } from "./CookieRequest";
9
+ import { ExportedCookie } from "./ExportedCookie";
8
10
  import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
9
11
  import { fetchWithCookies } from "./fetchWithCookies";
10
12
 
11
- export async function getCookie(params: { name: string; domain: string; }) {
13
+ export async function getCookie(params: CookieRequest): Promise<ExportedCookie | undefined> {
12
14
  const cookies = await queryCookies(
13
15
  params,
14
16
  new CompositeCookieQueryStrategy()
@@ -21,12 +23,7 @@ export async function getCookie(params: { name: string; domain: string; }) {
21
23
  }
22
24
  }
23
25
 
24
- /**
25
- *
26
- * @param params
27
- * @returns {Promise<*>}
28
- */
29
- export async function getFirefoxCookie(params: { name: string; domain: string; }) {
26
+ export async function getFirefoxCookie(params: CookieRequest): Promise<ExportedCookie | undefined> {
30
27
  const cookies = await queryCookies(
31
28
  params,
32
29
  new FirefoxCookieQueryStrategy()
@@ -39,12 +36,7 @@ export async function getFirefoxCookie(params: { name: string; domain: string; }
39
36
  }
40
37
  }
41
38
 
42
- /**
43
- *
44
- * @param params
45
- * @returns {Promise<*>}
46
- */
47
- export async function getChromeCookie(params: { name: string; domain: string; }) {
39
+ export async function getChromeCookie(params: CookieRequest): Promise<ExportedCookie | undefined> {
48
40
  const cookies = await queryCookies(
49
41
  params,
50
42
  new ChromeCookieQueryStrategy()
@@ -57,10 +49,11 @@ export async function getChromeCookie(params: { name: string; domain: string; })
57
49
  }
58
50
  }
59
51
 
60
- export default {
61
- getCookie,
62
- getFirefoxCookie,
63
- getChromeCookie,
52
+ export {
64
53
  getGroupedRenderedCookies,
65
- fetchWithCookies
66
- }
54
+ fetchWithCookies,
55
+ };
56
+
57
+ export * from "./CookieRequest";
58
+ export * from "./CookieRow";
59
+ export * from "./ExportedCookie";
@@ -3,8 +3,8 @@ import { uniqBy } from "lodash";
3
3
  import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
4
4
  import CookieQueryStrategy from "./browsers/CookieQueryStrategy";
5
5
  import isValidJwt from "./isValidJwt";
6
- import ExportedCookie from "./ExportedCookie";
7
- import CookieRequest from "./CookieRequest";
6
+ import { CookieRequest } from "./CookieRequest";
7
+ import { ExportedCookie } from "./ExportedCookie";
8
8
 
9
9
  export async function queryCookies(
10
10
  {
@@ -1,5 +1,5 @@
1
- import ExportedCookie from "./ExportedCookie";
2
1
  import { uniqBy } from "lodash";
2
+ import { ExportedCookie } from "./ExportedCookie";
3
3
 
4
4
  export function resultsRendered(results: ExportedCookie[]) {
5
5
  return uniqBy(results, (r) => r.name)