@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.
- package/.parcelrc +2 -7
- package/bun.lockb +0 -0
- package/dist/cli.js +18319 -2
- package/dist/index.js +24914 -1
- package/dist/types.d.ts +361 -30
- package/package-lock.json +3997 -6448
- package/package.json +8 -54
- package/src/CookieRow.ts +35 -7
- package/src/CookieSpec.ts +32 -14
- package/src/SpecialCases.ts +6 -5
- package/src/StringToRegex.ts +4 -4
- package/src/browsers/CompositeCookieQueryStrategy.ts +34 -28
- package/src/browsers/CookieQueryStrategy.ts +1 -1
- package/src/browsers/CookieStoreQueryStrategy.ts +71 -55
- package/src/browsers/QuerySqliteThenTransform.ts +27 -64
- package/src/browsers/chrome/ChromeApplicationSupport.ts +4 -0
- package/src/browsers/chrome/ChromeCookieQueryStrategy.ts +118 -91
- package/src/browsers/chrome/decrypt.ts +133 -97
- package/src/browsers/chrome/getChromePassword.ts +22 -5
- package/src/browsers/firefox/FirefoxCookieQueryStrategy.ts +19 -13
- package/src/browsers/getEncryptedChromeCookie.ts +101 -66
- package/src/browsers/mock/MockCookieQueryStrategy.ts +8 -4
- package/src/browsers/safari/SafariCookieQueryStrategy.ts +34 -3
- package/src/cli.ts +36 -29
- package/src/cliQueryCookies.ts +14 -4
- package/src/comboQueryCookieSpec.ts +7 -10
- package/src/cookieQueryOptions.ts +8 -1
- package/src/cookieSpecsFromUrl.ts +53 -7
- package/src/decodeBinaryCookies.ts +72 -0
- package/src/execSimple.ts +1 -2
- package/src/fetchWithCookies.ts +172 -144
- package/src/findAllFiles.ts +10 -0
- package/src/getChromeCookie.ts +6 -8
- package/src/getCookie.ts +8 -8
- package/src/getFirefoxCookie.ts +13 -9
- package/src/getGroupedRenderedCookies.ts +29 -6
- package/src/getMergedRenderedCookies.ts +4 -2
- package/src/global.ts +2 -2
- package/src/index.ts +16 -6
- package/src/isValidJwt.ts +6 -4
- package/src/listChromeProfiles.ts +18 -10
- package/src/logger.ts +0 -1
- package/src/processBeforeReturn.ts +15 -12
- package/src/queryCookies.ts +22 -17
- package/src/resultsRendered.ts +20 -7
- package/src/unpackHeaders.ts +10 -8
- package/src/util/flatMapAsync.ts +20 -16
- package/tsconfig.json +4 -4
- package/dist/index.js.map +0 -1
- package/dist/module.js +0 -1446
- package/dist/module.js.map +0 -1
- package/dist/prompt.2b8c61c0.js +0 -40
- package/dist/prompt.536a2c51.js +0 -40
- package/dist/prompt.fb2c7dad.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/src/CookieStore.ts +0 -27
- package/src/FileCookieStore.ts +0 -178
package/src/queryCookies.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
33
|
-
}
|
|
34
|
-
|
|
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
|
}
|
package/src/resultsRendered.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { orderBy, uniqBy } from "lodash";
|
|
2
2
|
import ExportedCookie from "./ExportedCookie";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
}
|
package/src/unpackHeaders.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
export function unpackHeaders(
|
|
2
|
-
|
|
3
|
-
|
|
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 (
|
|
8
|
-
const [key, value] =
|
|
9
|
+
for (let i = 0; i < headerArgs.length; i++) {
|
|
10
|
+
const [key, value] = headerArgs[i].split("=");
|
|
9
11
|
headers[key] = value;
|
|
10
12
|
}
|
|
11
|
-
|
|
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
|
}
|
package/src/util/flatMapAsync.ts
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
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
|
|
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:
|
|
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()
|
|
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
|
}
|