@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/package.json
CHANGED
|
@@ -1,59 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mherod/get-cookie",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
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",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
|
-
"module": "dist/module.js",
|
|
9
8
|
"types": "dist/types.d.ts",
|
|
10
9
|
"publishConfig": {
|
|
11
10
|
"access": "public"
|
|
12
11
|
},
|
|
13
12
|
"scripts": {
|
|
14
13
|
"clean": "git clean -fdX && rm -rf dist && yarn install",
|
|
15
|
-
"lintfix": "prettier --write \"src/**/*.ts\"",
|
|
16
|
-
"prebuild": "npm run lintfix",
|
|
17
14
|
"tsc": "tsc",
|
|
18
|
-
"build": "
|
|
19
|
-
"prepare": "parcel build --no-cache",
|
|
15
|
+
"build": "bun build src/index.ts --target=node --outdir=dist && bun build src/cli.ts --target=node --outdir=dist && tsc --emitDeclarationOnly",
|
|
20
16
|
"test": "jest",
|
|
21
|
-
"prepublish": "
|
|
22
|
-
"install:global": "
|
|
23
|
-
"prettier": "prettier --write ."
|
|
24
|
-
|
|
25
|
-
"targets": {
|
|
26
|
-
"types": {},
|
|
27
|
-
"main": {
|
|
28
|
-
"source": "src/index.ts",
|
|
29
|
-
"distDir": "dist",
|
|
30
|
-
"isLibrary": true,
|
|
31
|
-
"engines": {
|
|
32
|
-
"node": ">= 16"
|
|
33
|
-
},
|
|
34
|
-
"sourceMap": false,
|
|
35
|
-
"optimize": true,
|
|
36
|
-
"includeNodeModules": {
|
|
37
|
-
"@mapbox/node-pre-gyp": false
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
"cli": {
|
|
41
|
-
"source": "src/cli.ts",
|
|
42
|
-
"distDir": "dist",
|
|
43
|
-
"isLibrary": false,
|
|
44
|
-
"engines": {
|
|
45
|
-
"node": ">= 16"
|
|
46
|
-
},
|
|
47
|
-
"sourceMap": false,
|
|
48
|
-
"optimize": true,
|
|
49
|
-
"includeNodeModules": {
|
|
50
|
-
"@mapbox/node-pre-gyp": false
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
"@parcel/transformer-js": {
|
|
55
|
-
"inlineFS": false,
|
|
56
|
-
"inlineEnvironment": true
|
|
17
|
+
"prepublish": "bun run build",
|
|
18
|
+
"install:global": "bun run build && npm install --global .",
|
|
19
|
+
"prettier": "prettier --write .",
|
|
20
|
+
"copy-files": "cp -r src/cli.js dist/cli.js && cp -r src/index.js dist/index.js && cp -r src/types.d.ts dist/types.d.ts"
|
|
57
21
|
},
|
|
58
22
|
"engines": {
|
|
59
23
|
"node": ">= 16"
|
|
@@ -71,32 +35,22 @@
|
|
|
71
35
|
"lodash-es": "^4.17.21",
|
|
72
36
|
"lru-cache": "^7.14.0",
|
|
73
37
|
"minimist": "^1.2.7",
|
|
74
|
-
"sqlite3": "^5.1.6",
|
|
75
38
|
"tough-cookie": "^4.1.2"
|
|
76
39
|
},
|
|
77
40
|
"devDependencies": {
|
|
78
41
|
"@jest/globals": "^29.7.0",
|
|
79
|
-
"@
|
|
80
|
-
"@parcel/packager-ts": "^2.10.1",
|
|
81
|
-
"@parcel/transformer-typescript-tsc": "^2.10.1",
|
|
82
|
-
"@parcel/transformer-typescript-types": "^2.10.1",
|
|
42
|
+
"@types/bun": "^1.1.3",
|
|
83
43
|
"@types/jest": "^29.5.6",
|
|
84
44
|
"@types/jsonwebtoken": "^8.5.9",
|
|
85
45
|
"@types/lodash": "^4.14.186",
|
|
86
46
|
"@types/minimist": "^1.2.2",
|
|
87
|
-
"@types/node": "^18.
|
|
47
|
+
"@types/node": "^18.19.34",
|
|
88
48
|
"@types/tough-cookie": "^4.0.2",
|
|
89
49
|
"@types/user-agents": "^1.0.2",
|
|
90
50
|
"jest": "^29.7.0",
|
|
91
|
-
"parcel": "^2.10.1",
|
|
92
51
|
"prettier": "^3.0.3",
|
|
93
52
|
"ts-jest": "^29.1.1",
|
|
94
53
|
"ts-node": "^10.9.1",
|
|
95
54
|
"typescript": "^5.1.6"
|
|
96
|
-
},
|
|
97
|
-
"parcelDependencies": {
|
|
98
|
-
"@parcel/transformer-typescript-tsc": "^2.10.1",
|
|
99
|
-
"@parcel/transformer-typescript-types": "^2.10.1",
|
|
100
|
-
"@parcel/packager-ts": "^2.10.1"
|
|
101
55
|
}
|
|
102
56
|
}
|
package/src/CookieRow.ts
CHANGED
|
@@ -1,15 +1,43 @@
|
|
|
1
|
+
import consola from "./logger";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The CookieRow interface represents the structure of a cookie row object.
|
|
5
|
+
*/
|
|
1
6
|
export default interface CookieRow {
|
|
2
7
|
expiry?: number;
|
|
3
8
|
domain: string;
|
|
4
9
|
name: string;
|
|
5
|
-
value: Buffer;
|
|
6
|
-
meta?:
|
|
10
|
+
value: Uint8Array | Buffer;
|
|
11
|
+
meta?: Record<string, unknown>;
|
|
7
12
|
}
|
|
8
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Type guard to check if an object is a CookieRow.
|
|
16
|
+
* @param obj - The object to check.
|
|
17
|
+
* @returns True if the object is a CookieRow, false otherwise.
|
|
18
|
+
*/
|
|
9
19
|
export function isCookieRow(obj: any): obj is CookieRow {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
if (typeof obj !== "object" || obj === null) {
|
|
21
|
+
consola.warn("Object is not an object or is null:", obj);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { domain, name, value } = obj as CookieRow;
|
|
26
|
+
|
|
27
|
+
if (typeof domain !== "string") {
|
|
28
|
+
consola.warn("Domain is not a string:", domain);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof name !== "string") {
|
|
33
|
+
consola.warn("Name is not a string:", name);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!(value instanceof Uint8Array) && !Buffer.isBuffer(value)) {
|
|
38
|
+
consola.warn("Value is not a Uint8Array or Buffer:", value);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return true;
|
|
15
43
|
}
|
package/src/CookieSpec.ts
CHANGED
|
@@ -1,24 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Define the CookieSpec interface with domain and name properties
|
|
3
|
+
*/
|
|
2
4
|
export default interface CookieSpec {
|
|
3
5
|
domain: string;
|
|
4
6
|
name: string;
|
|
5
7
|
}
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Function to check if an object is of type CookieSpec
|
|
11
|
+
* @param obj - The object to check
|
|
12
|
+
* @returns True if the object is of type CookieSpec, otherwise false
|
|
13
|
+
*/
|
|
14
|
+
export function isCookieSpec(obj: unknown): obj is CookieSpec {
|
|
15
|
+
const cookie = obj as CookieSpec;
|
|
16
|
+
return typeof cookie.domain === "string" && typeof cookie.name === "string";
|
|
13
17
|
}
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Define a type that can be either a single CookieSpec or an array of CookieSpecs
|
|
21
|
+
*/
|
|
16
22
|
export type MultiCookieSpec = CookieSpec | CookieSpec[];
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Function to check if an object is of type MultiCookieSpec
|
|
26
|
+
* @param obj - The object to check
|
|
27
|
+
* @returns True if the object is of type MultiCookieSpec, otherwise false
|
|
28
|
+
*/
|
|
29
|
+
export function isMultiCookieSpec(obj: unknown): obj is MultiCookieSpec {
|
|
30
|
+
if (isCookieSpec(obj)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(obj)) {
|
|
34
|
+
for (let i = 0; i < obj.length; i++) {
|
|
35
|
+
if (!isCookieSpec(obj[i])) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
24
42
|
}
|
package/src/SpecialCases.ts
CHANGED
|
@@ -3,12 +3,13 @@ import CookieSpec from "./CookieSpec";
|
|
|
3
3
|
export function specialCases({ name, domain }: CookieSpec): {
|
|
4
4
|
specifiedName: boolean;
|
|
5
5
|
specifiedDomain: boolean;
|
|
6
|
-
//
|
|
7
6
|
} {
|
|
8
|
-
const wildcardRegexp = /^([*%])$/i;
|
|
7
|
+
const wildcardRegexp: RegExp = /^([*%])$/i;
|
|
8
|
+
const specifiedName: boolean = name.match(wildcardRegexp) == null;
|
|
9
|
+
const specifiedDomain: boolean = domain.match(wildcardRegexp) == null;
|
|
10
|
+
|
|
9
11
|
return {
|
|
10
|
-
specifiedName
|
|
11
|
-
specifiedDomain
|
|
12
|
-
//
|
|
12
|
+
specifiedName,
|
|
13
|
+
specifiedDomain,
|
|
13
14
|
};
|
|
14
15
|
}
|
package/src/StringToRegex.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// This function converts a string into a regular expression
|
|
2
2
|
export function stringToRegex(s: string): RegExp {
|
|
3
|
-
// Replace all occurrences of '.' with a literal '
|
|
4
|
-
|
|
3
|
+
// Replace all occurrences of '.' with a literal '\.'
|
|
4
|
+
let s1: string = s.replace(/\./g, "\\.");
|
|
5
5
|
// Replace all occurrences of '%' with '.*' to match any number of any characters
|
|
6
|
-
|
|
6
|
+
let s2: string = s1.replace(/%/g, ".*");
|
|
7
7
|
// Replace all occurrences of '*' with '.*' to match any number of any characters
|
|
8
|
-
|
|
8
|
+
let s3: string = s2.replace(/\*/g, ".*");
|
|
9
9
|
// Return the new string as a RegExp object
|
|
10
10
|
return new RegExp(s3);
|
|
11
11
|
}
|
|
@@ -5,9 +5,8 @@ import CookieQueryStrategy from "./CookieQueryStrategy";
|
|
|
5
5
|
import ExportedCookie from "../ExportedCookie";
|
|
6
6
|
import LRUCache from "lru-cache";
|
|
7
7
|
import { merge } from "lodash";
|
|
8
|
-
import { parsedArgs } from "../argv";
|
|
9
|
-
import consola from "consola";
|
|
10
8
|
import { flatMapAsync } from "../util/flatMapAsync";
|
|
9
|
+
import consola from "../logger";
|
|
11
10
|
|
|
12
11
|
const cache: LRUCache<string, ExportedCookie[]> = new LRUCache<
|
|
13
12
|
string,
|
|
@@ -20,51 +19,58 @@ const cache: LRUCache<string, ExportedCookie[]> = new LRUCache<
|
|
|
20
19
|
export default class CompositeCookieQueryStrategy
|
|
21
20
|
implements CookieQueryStrategy
|
|
22
21
|
{
|
|
23
|
-
browserName = "all";
|
|
22
|
+
browserName: string = "all";
|
|
24
23
|
|
|
25
|
-
private readonly strategies;
|
|
24
|
+
private readonly strategies: CookieQueryStrategy[];
|
|
26
25
|
|
|
27
26
|
constructor() {
|
|
28
27
|
this.strategies = [
|
|
29
|
-
// CookieStoreQueryStrategy,
|
|
30
28
|
ChromeCookieQueryStrategy,
|
|
31
29
|
FirefoxCookieQueryStrategy,
|
|
32
30
|
SafariCookieQueryStrategy,
|
|
33
|
-
].map((
|
|
34
|
-
return new strategy();
|
|
35
|
-
});
|
|
31
|
+
].map((Strategy) => new Strategy());
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
const key: string = `${name}:${domain}`;
|
|
36
|
+
consola.info(`Querying cookies for name: ${name}, domain: ${domain}`);
|
|
41
37
|
if (cache.has(key)) {
|
|
42
|
-
const cached = cache.get(key);
|
|
38
|
+
const cached: ExportedCookie[] | undefined = cache.get(key);
|
|
43
39
|
if (cached) {
|
|
40
|
+
consola.info(
|
|
41
|
+
`Cache hit for key: ${key}, returning ${cached.length} cookies`,
|
|
42
|
+
);
|
|
44
43
|
return cached;
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
const results: ExportedCookie[] = await flatMapAsync(
|
|
47
|
+
this.strategies,
|
|
48
|
+
async (strategy) => {
|
|
49
|
+
try {
|
|
50
|
+
const cookies: ExportedCookie[] = await strategy.queryCookies(
|
|
51
|
+
name,
|
|
52
|
+
domain,
|
|
53
|
+
);
|
|
54
|
+
return cookies.map((cookie: ExportedCookie) =>
|
|
55
|
+
merge(cookie, {
|
|
56
56
|
meta: {
|
|
57
57
|
browser: strategy.browserName,
|
|
58
58
|
},
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
consola.error(
|
|
63
|
+
`Error querying cookies for ${name} on ${domain} using ${strategy.browserName}`,
|
|
64
|
+
e,
|
|
65
|
+
);
|
|
64
66
|
return [];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
cache.set(key, results);
|
|
71
|
+
consola.info(
|
|
72
|
+
`Query result size for key: ${key} is ${results.length} cookies`,
|
|
73
|
+
);
|
|
68
74
|
return results;
|
|
69
75
|
}
|
|
70
76
|
}
|
|
@@ -3,5 +3,5 @@ import ExportedCookie from "../ExportedCookie";
|
|
|
3
3
|
export default interface CookieQueryStrategy {
|
|
4
4
|
browserName: string;
|
|
5
5
|
|
|
6
|
-
queryCookies(name: string, domain: string): Promise<ExportedCookie
|
|
6
|
+
queryCookies(name: string, domain: string): Promise<Array<ExportedCookie>>;
|
|
7
7
|
}
|
|
@@ -6,55 +6,76 @@ import { cookieJarPromise, cookieStorePromise } from "../CookieStore";
|
|
|
6
6
|
import { stringToRegex } from "../StringToRegex";
|
|
7
7
|
|
|
8
8
|
export default class CookieStoreQueryStrategy implements CookieQueryStrategy {
|
|
9
|
-
browserName = "internal";
|
|
9
|
+
browserName: string = "internal";
|
|
10
10
|
|
|
11
11
|
async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
|
|
12
|
-
const exportedCookies: ExportedCookie[] =
|
|
12
|
+
const exportedCookies: ExportedCookie[] = await this.getAllExportedCookies(
|
|
13
|
+
name,
|
|
14
|
+
domain,
|
|
15
|
+
);
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
const cookies: Cookie[] = await this.#getAllCookies();
|
|
16
|
-
const allExportedCookies = cookies.map((cookie: Cookie) => {
|
|
17
|
-
return this.#extracted(cookie, { name, domain });
|
|
18
|
-
});
|
|
19
|
-
exportedCookies.push(...allExportedCookies);
|
|
20
|
-
// }
|
|
21
|
-
|
|
22
|
-
const wildcardRegexp = /^([*%])$/i;
|
|
17
|
+
const wildcardRegexp: RegExp = /^([*%])$/i;
|
|
23
18
|
if (name.match(wildcardRegexp) && domain.match(wildcardRegexp)) {
|
|
24
19
|
return exportedCookies;
|
|
25
20
|
}
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
url.pathname = path;
|
|
33
|
-
const cookies: Cookie[] = await this.#getCookies(url.href);
|
|
34
|
-
const domainCookies = cookies.map((cookie: Cookie) => {
|
|
35
|
-
return this.#extracted(cookie, {
|
|
36
|
-
domain,
|
|
37
|
-
name,
|
|
38
|
-
});
|
|
39
|
-
});
|
|
22
|
+
if (domain !== "%") {
|
|
23
|
+
const domainCookies: ExportedCookie[] = await this.getDomainCookies(
|
|
24
|
+
name,
|
|
25
|
+
domain,
|
|
26
|
+
);
|
|
40
27
|
exportedCookies.push(...domainCookies);
|
|
41
28
|
}
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
return this.filterCookies(exportedCookies, name, domain);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private async getAllExportedCookies(
|
|
34
|
+
name: string,
|
|
35
|
+
domain: string,
|
|
36
|
+
): Promise<ExportedCookie[]> {
|
|
37
|
+
const cookies: Cookie[] = await this.getAllCookies();
|
|
38
|
+
return cookies.map((cookie: Cookie) =>
|
|
39
|
+
this.extractCookie(cookie, { name, domain }),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private async getDomainCookies(
|
|
44
|
+
name: string,
|
|
45
|
+
domain: string,
|
|
46
|
+
): Promise<ExportedCookie[]> {
|
|
47
|
+
const path: string = "/";
|
|
48
|
+
const domain1: string = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
|
|
49
|
+
const url: URL = new URL("https://" + domain1);
|
|
50
|
+
url.pathname = path;
|
|
51
|
+
const cookies: Cookie[] = await this.getCookies(url.href);
|
|
52
|
+
return cookies.map((cookie: Cookie) =>
|
|
53
|
+
this.extractCookie(cookie, { domain, name }),
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private filterCookies(
|
|
58
|
+
exportedCookies: ExportedCookie[],
|
|
59
|
+
name: string,
|
|
60
|
+
domain: string,
|
|
61
|
+
): ExportedCookie[] {
|
|
62
|
+
if (name === "%") {
|
|
63
|
+
return exportedCookies.filter((cookie: ExportedCookie) =>
|
|
64
|
+
cookie.domain.match(stringToRegex(domain)),
|
|
65
|
+
);
|
|
47
66
|
}
|
|
48
67
|
|
|
49
|
-
return exportedCookies.filter(
|
|
50
|
-
|
|
68
|
+
return exportedCookies.filter(
|
|
69
|
+
(cookie: ExportedCookie) =>
|
|
51
70
|
cookie.name.match(stringToRegex(name)) &&
|
|
52
|
-
cookie.domain.match(stringToRegex(domain))
|
|
53
|
-
|
|
54
|
-
});
|
|
71
|
+
cookie.domain.match(stringToRegex(domain)),
|
|
72
|
+
);
|
|
55
73
|
}
|
|
56
74
|
|
|
57
|
-
|
|
75
|
+
private extractCookie(
|
|
76
|
+
cookie: Cookie,
|
|
77
|
+
cookieSpec: CookieSpec,
|
|
78
|
+
): ExportedCookie {
|
|
58
79
|
return {
|
|
59
80
|
domain: cookie.domain ?? cookieSpec.domain,
|
|
60
81
|
name: cookie.key ?? cookieSpec.name,
|
|
@@ -66,34 +87,29 @@ export default class CookieStoreQueryStrategy implements CookieQueryStrategy {
|
|
|
66
87
|
};
|
|
67
88
|
}
|
|
68
89
|
|
|
69
|
-
async
|
|
90
|
+
private async getCookies(url: string): Promise<Cookie[]> {
|
|
70
91
|
const cookieJar = await cookieJarPromise;
|
|
71
92
|
return new Promise((resolve, reject) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
);
|
|
93
|
+
cookieJar.getCookies(url, (err: Error | null, cookies: Cookie[]) => {
|
|
94
|
+
if (err) {
|
|
95
|
+
reject(err);
|
|
96
|
+
} else {
|
|
97
|
+
resolve(cookies ?? []);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
82
100
|
});
|
|
83
101
|
}
|
|
84
102
|
|
|
85
|
-
async
|
|
103
|
+
private async getAllCookies(): Promise<Cookie[]> {
|
|
86
104
|
const cookieStore: Store = await cookieStorePromise;
|
|
87
105
|
return new Promise((resolve, reject) => {
|
|
88
|
-
|
|
89
|
-
(err
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
},
|
|
96
|
-
);
|
|
106
|
+
cookieStore.getAllCookies((err: Error | null, cookies: Cookie[]) => {
|
|
107
|
+
if (err) {
|
|
108
|
+
reject(err);
|
|
109
|
+
} else {
|
|
110
|
+
resolve(cookies ?? []);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
97
113
|
});
|
|
98
114
|
}
|
|
99
115
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import CookieRow from "../CookieRow";
|
|
2
2
|
import fs from "fs";
|
|
3
|
-
import { Database } from "sqlite3";
|
|
4
3
|
import { merge } from "lodash";
|
|
5
|
-
import {
|
|
6
|
-
import consola from "../logger";
|
|
4
|
+
import { Database } from "bun:sqlite";
|
|
7
5
|
|
|
8
6
|
interface FnOptions {
|
|
9
7
|
file: string;
|
|
@@ -12,74 +10,39 @@ interface FnOptions {
|
|
|
12
10
|
rowTransform: (row: any) => CookieRow;
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
function checkFileExistence(file: string) {
|
|
16
|
-
if (!file || !fs.existsSync(file))
|
|
13
|
+
async function checkFileExistence(file: string): Promise<void> {
|
|
14
|
+
if (!file || !fs.existsSync(file))
|
|
17
15
|
throw new Error(`File ${file} does not exist`);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function createDatabase(file: string): Database {
|
|
22
|
-
return new Database(file);
|
|
23
16
|
}
|
|
24
17
|
|
|
25
|
-
function transformRows(
|
|
26
|
-
//
|
|
18
|
+
async function transformRows(
|
|
27
19
|
rows: any[],
|
|
28
20
|
rowFilter: (row: any) => boolean,
|
|
29
21
|
rowTransform: (row: any) => CookieRow,
|
|
30
22
|
file: string,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const cookieRow: CookieRow = rowTransform(row);
|
|
41
|
-
|
|
42
|
-
return merge(metaData, cookieRow);
|
|
43
|
-
});
|
|
23
|
+
): Promise<CookieRow[]> {
|
|
24
|
+
const filteredRows = rows.filter(rowFilter);
|
|
25
|
+
const transformedRows = filteredRows.map((row) =>
|
|
26
|
+
merge({ meta: { file } }, rowTransform(row)),
|
|
27
|
+
);
|
|
28
|
+
return transformedRows;
|
|
44
29
|
}
|
|
45
30
|
|
|
46
|
-
export async function querySqliteThenTransform(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (err) {
|
|
64
|
-
return reject(err);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!rows || rows.length === 0) {
|
|
68
|
-
return resolve([]);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const cookieRows: CookieRow[] = transformRows(
|
|
72
|
-
rows,
|
|
73
|
-
rowFilter,
|
|
74
|
-
rowTransform,
|
|
75
|
-
file,
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
if (parsedArgs.verbose) {
|
|
79
|
-
consola.log(`Rows: ${JSON.stringify(rows)}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return resolve(cookieRows);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
31
|
+
export async function querySqliteThenTransform({
|
|
32
|
+
file,
|
|
33
|
+
sql,
|
|
34
|
+
rowFilter = () => true,
|
|
35
|
+
rowTransform,
|
|
36
|
+
}: FnOptions): Promise<CookieRow[]> {
|
|
37
|
+
await checkFileExistence(file);
|
|
38
|
+
const db = new Database(file);
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const rows: any[] = db.query(sql).all();
|
|
42
|
+
if (!rows || rows.length === 0) return [];
|
|
43
|
+
|
|
44
|
+
return await transformRows(rows, rowFilter, rowTransform, file);
|
|
45
|
+
} catch (err: any) {
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
85
48
|
}
|