@mherod/get-cookie 2.1.1 → 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 +24754 -1300
  5. package/dist/types.d.ts +361 -30
  6. package/package-lock.json +3997 -6448
  7. package/package.json +8 -52
  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
package/package.json CHANGED
@@ -1,57 +1,23 @@
1
1
  {
2
2
  "name": "@mherod/get-cookie",
3
- "version": "2.1.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": "parcel build --no-cache",
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": "npm run build",
22
- "install:global": "npm run build && npm 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": true,
35
- "optimize": false,
36
- "includeNodeModules": false
37
- },
38
- "cli": {
39
- "source": "src/cli.ts",
40
- "distDir": "dist",
41
- "isLibrary": false,
42
- "engines": {
43
- "node": ">= 16"
44
- },
45
- "sourceMap": false,
46
- "optimize": true,
47
- "includeNodeModules": {
48
- "@mapbox/node-pre-gyp": false
49
- }
50
- }
51
- },
52
- "@parcel/transformer-js": {
53
- "inlineFS": false,
54
- "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"
55
21
  },
56
22
  "engines": {
57
23
  "node": ">= 16"
@@ -69,32 +35,22 @@
69
35
  "lodash-es": "^4.17.21",
70
36
  "lru-cache": "^7.14.0",
71
37
  "minimist": "^1.2.7",
72
- "sqlite3": "^5.1.6",
73
38
  "tough-cookie": "^4.1.2"
74
39
  },
75
40
  "devDependencies": {
76
41
  "@jest/globals": "^29.7.0",
77
- "@mapbox/node-pre-gyp": "^1.0.11",
78
- "@parcel/packager-ts": "^2.10.1",
79
- "@parcel/transformer-typescript-tsc": "^2.10.1",
80
- "@parcel/transformer-typescript-types": "^2.10.1",
42
+ "@types/bun": "^1.1.3",
81
43
  "@types/jest": "^29.5.6",
82
44
  "@types/jsonwebtoken": "^8.5.9",
83
45
  "@types/lodash": "^4.14.186",
84
46
  "@types/minimist": "^1.2.2",
85
- "@types/node": "^18.11.4",
47
+ "@types/node": "^18.19.34",
86
48
  "@types/tough-cookie": "^4.0.2",
87
49
  "@types/user-agents": "^1.0.2",
88
50
  "jest": "^29.7.0",
89
- "parcel": "^2.10.1",
90
51
  "prettier": "^3.0.3",
91
52
  "ts-jest": "^29.1.1",
92
53
  "ts-node": "^10.9.1",
93
54
  "typescript": "^5.1.6"
94
- },
95
- "parcelDependencies": {
96
- "@parcel/transformer-typescript-tsc": "^2.10.1",
97
- "@parcel/transformer-typescript-types": "^2.10.1",
98
- "@parcel/packager-ts": "^2.10.1"
99
55
  }
100
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?: any;
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
- return (
11
- obj.domain !== undefined &&
12
- obj.name !== undefined &&
13
- obj.value !== undefined
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
- // Define the CookieSpec interface with domain and name properties
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
- // Function to check if an object is of type CookieSpec
8
- export function isCookieSpec(obj: any): obj is CookieSpec {
9
- return (
10
- // Check if domain and name properties are of type string
11
- typeof obj.domain === "string" && typeof obj.name === "string"
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
- // Define a type that can be either a single CookieSpec or an array of CookieSpecs
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
- // Function to check if an object is of type MultiCookieSpec
19
- export function isMultiCookieSpec(obj: any): obj is MultiCookieSpec {
20
- return (
21
- // Check if the object is a CookieSpec or an array of CookieSpecs
22
- isCookieSpec(obj) || (Array.isArray(obj) && obj.every(isCookieSpec))
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
  }
@@ -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: name.match(wildcardRegexp) == null,
11
- specifiedDomain: domain.match(wildcardRegexp) == null,
12
- //
12
+ specifiedName,
13
+ specifiedDomain,
13
14
  };
14
15
  }
@@ -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
- const s1 = s.replaceAll(/\./gi, ".");
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
- const s2 = s1.replace(/%/g, ".*");
6
+ let s2: string = s1.replace(/%/g, ".*");
7
7
  // Replace all occurrences of '*' with '.*' to match any number of any characters
8
- const s3 = s2.replace(/\*/g, ".*");
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((strategy) => {
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
- // domain = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
40
- const key = `${name}:${domain}`;
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
- if (parsedArgs.verbose) {
48
- consola.log("Querying cookies:", name, domain);
49
- }
50
- const results = await flatMapAsync(this.strategies, async (strategy) => {
51
- return strategy
52
- .queryCookies(name, domain)
53
- .then((cookies: ExportedCookie[]) => {
54
- return cookies.map((cookie: ExportedCookie) => {
55
- return merge(cookie, {
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
- .catch((e) => {
63
- consola.error(`Error querying ${strategy.browserName} cookies`, e);
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
- cache.set(`${name}:${domain}`, results);
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
- // if (name.match(/[%*]/) || domain.match(/[%*]/)) {
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
- const path = "/";
28
-
29
- if (domain != "%") {
30
- const domain1 = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
31
- const url = new URL("https://" + domain1);
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
- if (name == "%") {
44
- return exportedCookies.filter((cookie: ExportedCookie) => {
45
- return cookie.domain.match(stringToRegex(domain));
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((cookie: ExportedCookie) => {
50
- return (
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
- #extracted(cookie: Cookie, cookieSpec: CookieSpec): ExportedCookie {
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 #getCookies(url: string): Promise<Cookie[]> {
90
+ private async getCookies(url: string): Promise<Cookie[]> {
70
91
  const cookieJar = await cookieJarPromise;
71
92
  return new Promise((resolve, reject) => {
72
- return cookieJar.getCookies(
73
- url,
74
- (err: Error | null, cookies: Cookie[]) => {
75
- if (err) {
76
- reject(err);
77
- } else {
78
- resolve(cookies ?? []);
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 #getAllCookies(): Promise<Cookie[]> {
103
+ private async getAllCookies(): Promise<Cookie[]> {
86
104
  const cookieStore: Store = await cookieStorePromise;
87
105
  return new Promise((resolve, reject) => {
88
- return cookieStore.getAllCookies(
89
- (err: Error | null, cookies: Cookie[]) => {
90
- if (err) {
91
- reject(err);
92
- } else {
93
- resolve(cookies ?? []);
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 { parsedArgs } from "../argv";
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
- ): CookieRow[] {
33
- return rows.filter(rowFilter).map((row: any) => {
34
- const metaData = {
35
- meta: {
36
- file: file,
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
- file,
51
- sql,
52
- rowFilter = () => true,
53
- rowTransform,
54
- }: FnOptions,
55
- ): //
56
- Promise<CookieRow[]> {
57
- checkFileExistence(file);
58
-
59
- const db: Database = createDatabase(file);
60
-
61
- return new Promise((resolve, reject) => {
62
- db.all(sql, (err: Error, rows: any[]) => {
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
  }
@@ -1,6 +1,10 @@
1
1
  import { join } from "path";
2
2
  import { HOME } from "../../global";
3
3
 
4
+ if (HOME === undefined) {
5
+ throw new Error("HOME environment variable is not defined");
6
+ }
7
+
4
8
  export const chromeApplicationSupport: string = join(
5
9
  HOME,
6
10
  "Library",