@mherod/get-cookie 2.1.0 → 2.1.2

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.
Files changed (57) hide show
  1. package/.parcelrc +2 -7
  2. package/bun.lockb +0 -0
  3. package/dist/cli.js +18319 -2
  4. package/dist/index.js +24914 -1
  5. package/dist/types.d.ts +361 -30
  6. package/package-lock.json +3997 -6448
  7. package/package.json +8 -54
  8. package/src/CookieRow.ts +35 -7
  9. package/src/CookieSpec.ts +32 -14
  10. package/src/SpecialCases.ts +6 -5
  11. package/src/StringToRegex.ts +4 -4
  12. package/src/browsers/CompositeCookieQueryStrategy.ts +34 -28
  13. package/src/browsers/CookieQueryStrategy.ts +1 -1
  14. package/src/browsers/CookieStoreQueryStrategy.ts +71 -55
  15. package/src/browsers/QuerySqliteThenTransform.ts +27 -64
  16. package/src/browsers/chrome/ChromeApplicationSupport.ts +4 -0
  17. package/src/browsers/chrome/ChromeCookieQueryStrategy.ts +118 -91
  18. package/src/browsers/chrome/decrypt.ts +133 -97
  19. package/src/browsers/chrome/getChromePassword.ts +22 -5
  20. package/src/browsers/firefox/FirefoxCookieQueryStrategy.ts +19 -13
  21. package/src/browsers/getEncryptedChromeCookie.ts +101 -66
  22. package/src/browsers/mock/MockCookieQueryStrategy.ts +8 -4
  23. package/src/browsers/safari/SafariCookieQueryStrategy.ts +34 -3
  24. package/src/cli.ts +36 -29
  25. package/src/cliQueryCookies.ts +14 -4
  26. package/src/comboQueryCookieSpec.ts +7 -10
  27. package/src/cookieQueryOptions.ts +8 -1
  28. package/src/cookieSpecsFromUrl.ts +53 -7
  29. package/src/decodeBinaryCookies.ts +72 -0
  30. package/src/execSimple.ts +1 -2
  31. package/src/fetchWithCookies.ts +172 -144
  32. package/src/findAllFiles.ts +10 -0
  33. package/src/getChromeCookie.ts +6 -8
  34. package/src/getCookie.ts +8 -8
  35. package/src/getFirefoxCookie.ts +13 -9
  36. package/src/getGroupedRenderedCookies.ts +29 -6
  37. package/src/getMergedRenderedCookies.ts +4 -2
  38. package/src/global.ts +2 -2
  39. package/src/index.ts +16 -6
  40. package/src/isValidJwt.ts +6 -4
  41. package/src/listChromeProfiles.ts +18 -10
  42. package/src/logger.ts +0 -1
  43. package/src/processBeforeReturn.ts +15 -12
  44. package/src/queryCookies.ts +22 -17
  45. package/src/resultsRendered.ts +20 -7
  46. package/src/unpackHeaders.ts +10 -8
  47. package/src/util/flatMapAsync.ts +20 -16
  48. package/tsconfig.json +4 -4
  49. package/dist/index.js.map +0 -1
  50. package/dist/module.js +0 -1446
  51. package/dist/module.js.map +0 -1
  52. package/dist/prompt.2b8c61c0.js +0 -40
  53. package/dist/prompt.536a2c51.js +0 -40
  54. package/dist/prompt.fb2c7dad.js.map +0 -1
  55. package/dist/types.d.ts.map +0 -1
  56. package/src/CookieStore.ts +0 -27
  57. package/src/FileCookieStore.ts +0 -178
@@ -3,34 +3,39 @@ import { parsedArgs } from "./argv";
3
3
  import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
4
4
  import CookieQueryStrategy from "./browsers/CookieQueryStrategy";
5
5
  import isValidJwt from "./isValidJwt";
6
- import CookieSpec, { MultiCookieSpec } from "./CookieSpec";
6
+ import CookieSpec from "./CookieSpec";
7
7
  import ExportedCookie from "./ExportedCookie";
8
8
  import { CookieQueryOptions } from "./cookieQueryOptions";
9
+ import consola from "./logger";
9
10
 
10
11
  export async function queryCookies(
11
- {
12
- name,
13
- domain,
14
- }: //
15
- CookieSpec,
12
+ { name, domain }: CookieSpec,
16
13
  options?: CookieQueryOptions<CookieQueryStrategy>,
17
14
  ): Promise<ExportedCookie[]> {
18
15
  const strategy: CookieQueryStrategy =
19
16
  options?.strategy || new CompositeCookieQueryStrategy();
20
- //
17
+
18
+ consola.debug(`Using strategy: ${strategy.browserName}`);
19
+
21
20
  const results: ExportedCookie[] = await strategy.queryCookies(name, domain);
22
21
  const allCookies: ExportedCookie[] = uniqBy(results, JSON.stringify);
23
22
 
24
- if (parsedArgs["require-jwt"]) {
25
- const jwtCookies = [];
26
- for (const result of allCookies) {
27
- const value: string = result.value;
28
- if (isValidJwt(value)) {
29
- jwtCookies.push(result);
23
+ const filterCookies = (
24
+ cookies: ExportedCookie[],
25
+ filterFn: (value: string) => boolean,
26
+ ): ExportedCookie[] => {
27
+ const filteredCookies: ExportedCookie[] = [];
28
+ for (const cookie of cookies) {
29
+ if (filterFn(cookie.value)) {
30
+ filteredCookies.push(cookie);
30
31
  }
31
32
  }
32
- return parsedArgs["single"] ? [jwtCookies[0]] : jwtCookies;
33
- } else {
34
- return parsedArgs["single"] ? [allCookies[0]] : allCookies;
35
- }
33
+ return filteredCookies;
34
+ };
35
+
36
+ const jwtCookies: ExportedCookie[] = parsedArgs["require-jwt"]
37
+ ? filterCookies(allCookies, isValidJwt)
38
+ : allCookies;
39
+
40
+ return parsedArgs["single"] ? [jwtCookies[0]] : jwtCookies;
36
41
  }
@@ -1,11 +1,24 @@
1
1
  import { orderBy, uniqBy } from "lodash";
2
2
  import ExportedCookie from "./ExportedCookie";
3
3
 
4
- export function resultsRendered(results: ExportedCookie[]) {
5
- // sort by name and expiry descending
6
- // takes the latest expiry for each name
7
- const orderedResults = orderBy(results, ["name", "expiry"], ["asc", "desc"]);
8
- return uniqBy(orderedResults, (r: ExportedCookie) => r.name)
9
- .map((r: ExportedCookie) => r.name + "=" + r.value)
10
- .join("; ");
4
+ function sortResults(results: ExportedCookie[]): ExportedCookie[] {
5
+ return orderBy(results, ["name", "expiry"], ["asc", "desc"]);
6
+ }
7
+
8
+ function getUniqueResults(results: ExportedCookie[]): ExportedCookie[] {
9
+ return uniqBy(results, "name");
10
+ }
11
+
12
+ function formatResults(results: ExportedCookie[]): string {
13
+ const resultStrings: string[] = [];
14
+ for (const result of results) {
15
+ resultStrings.push(`${result.name}=${result.value}`);
16
+ }
17
+ return resultStrings.join("; ");
18
+ }
19
+
20
+ export function resultsRendered(results: ExportedCookie[]): string {
21
+ const orderedResults: ExportedCookie[] = sortResults(results);
22
+ const uniqueResults: ExportedCookie[] = getUniqueResults(orderedResults);
23
+ return formatResults(uniqueResults);
11
24
  }
@@ -1,16 +1,18 @@
1
- export function unpackHeaders(headerArgs: string[] | string | null) {
2
- const headers: any = {};
3
- if (headerArgs == null) {
1
+ export function unpackHeaders(
2
+ headerArgs: string[] | string | null,
3
+ ): Record<string, string> {
4
+ const headers: Record<string, string> = {};
5
+ if (headerArgs === null) {
4
6
  return headers;
5
7
  }
6
8
  if (Array.isArray(headerArgs)) {
7
- for (const h of headerArgs) {
8
- const [key, value] = h.split("=");
9
+ for (let i = 0; i < headerArgs.length; i++) {
10
+ const [key, value] = headerArgs[i].split("=");
9
11
  headers[key] = value;
10
12
  }
11
- return headers;
13
+ } else {
14
+ const [key, value] = headerArgs.split("=");
15
+ headers[key] = value;
12
16
  }
13
- const [key, value] = headerArgs.split("=");
14
- headers[key] = value;
15
17
  return headers;
16
18
  }
@@ -3,35 +3,39 @@
3
3
 
4
4
  export async function flatMapAsync<T, O>(
5
5
  array: T[], // The input array to transform.
6
- callback: (value: T, index: number, array: T[]) => Promise<O[]>, // The async function to apply to each input array element.,
6
+ callback: (value: T, index: number, array: T[]) => Promise<O[]>, // The async function to apply to each input array element.
7
7
  or?: O[] | ((error: any) => O[] | Promise<O[]>), // An optional callback to handle errors.
8
8
  ): Promise<O[]> {
9
9
  if (or) {
10
- return flatMapAsync(
11
- array,
12
- async (value: T, index: number, array: T[]) => {
13
- try {
14
- return await callback(value, index, array);
15
- } catch (error) {
16
- return typeof or == "function" ? or(error) : or;
17
- }
18
- },
19
- //
20
- );
10
+ const errorHandlingCallback = async (
11
+ value: T,
12
+ index: number,
13
+ array: T[],
14
+ ): Promise<O[]> => {
15
+ try {
16
+ return await callback(value, index, array);
17
+ } catch (error) {
18
+ return typeof or === "function" ? await or(error) : or;
19
+ }
20
+ };
21
+ return flatMapAsync(array, errorHandlingCallback);
21
22
  }
22
23
 
23
- // Step 1: Use Array.prototype.map to transform each element of the input array with the provided callback.
24
+ // Step 1: Use a for loop to transform each element of the input array with the provided callback.
24
25
  // This will result in an array of promises.
25
- const ps: Promise<O>[] = array.map(callback) as Promise<O>[];
26
+ const promises: Promise<O[]>[] = [];
27
+ for (let i = 0; i < array.length; i++) {
28
+ promises.push(callback(array[i], i, array));
29
+ }
26
30
 
27
31
  // Step 2: Use Promise.all to wait for all promises in the array to fulfill.
28
32
  // This will give us an array of fulfilled promise values.
29
- const awaitedAll: Awaited<O>[] = await Promise.all(ps);
33
+ const awaitedAll: O[][] = await Promise.all(promises);
30
34
 
31
35
  // Step 3: Flatten the array of fulfilled promise values into a single array.
32
36
  // Note: The '@ts-ignore' comment is used to suppress TypeScript compiler warnings, as .flat() method might not be recognized
33
37
  // as a valid method for an array of Awaited<O> instances. However, this code assumes that the result of Promise.all
34
38
  // is indeed an array that can be flattened.
35
39
  // @ts-ignore
36
- return awaitedAll.flat() as O[];
40
+ return awaitedAll.flat();
37
41
  }
package/tsconfig.json CHANGED
@@ -5,12 +5,12 @@
5
5
  "src/**.js",
6
6
  "src/**.jsx",
7
7
  "src/**.test.ts",
8
- "src/**.test.js"
8
+ "src/**.test.js",
9
9
  ],
10
10
  "compilerOptions": {
11
11
  "moduleResolution": "node",
12
12
  "target": "es6",
13
- "types": ["node", "jest"],
13
+ "types": ["node", "jest", "bun-types"],
14
14
  "lib": ["es2015", "es2017", "es2021", "dom"],
15
15
  "strict": true,
16
16
  "skipDefaultLibCheck": true,
@@ -21,6 +21,6 @@
21
21
  "esModuleInterop": true,
22
22
  "module": "commonjs",
23
23
  "outDir": "dist",
24
- "outFile": "dist/types.d.ts"
25
- }
24
+ "outFile": "dist/types.d.ts",
25
+ },
26
26
  }