@mherod/get-cookie 2.0.0-rc.3 → 2.0.0-rc.30

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 (65) hide show
  1. package/.idea/runConfigurations/build.xml +12 -0
  2. package/.parcelrc +12 -0
  3. package/.prettierignore +5 -0
  4. package/.prettierrc +12 -0
  5. package/.terserrc +26 -0
  6. package/README.md +2 -2
  7. package/dist/cli.js +2 -0
  8. package/dist/index.js +2 -687
  9. package/dist/index.js.map +1 -0
  10. package/dist/module.js +1323 -0
  11. package/dist/module.js.map +1 -0
  12. package/dist/prompt.2b8c61c0.js +40 -0
  13. package/dist/prompt.536a2c51.js +40 -0
  14. package/dist/prompt.fb2c7dad.js.map +1 -0
  15. package/dist/types.d.ts +25 -0
  16. package/dist/types.d.ts.map +1 -0
  17. package/jest.config.ts +14 -0
  18. package/package-lock.json +2688 -6684
  19. package/package.json +42 -35
  20. package/src/CookieRow.ts +1 -0
  21. package/src/CookieSpec.ts +3 -1
  22. package/src/CookieStore.ts +27 -0
  23. package/src/ExportedCookie.ts +13 -0
  24. package/src/FetchResponse.ts +1 -2
  25. package/src/FileCookieStore.ts +175 -0
  26. package/src/StringToRegex.ts +16 -0
  27. package/src/argv.ts +29 -0
  28. package/src/browsers/ChromeApplicationSupport.ts +10 -0
  29. package/src/browsers/ChromeCookieQueryStrategy.ts +71 -131
  30. package/src/browsers/CompositeCookieQueryStrategy.ts +35 -11
  31. package/src/browsers/CookieQueryStrategy.ts +2 -0
  32. package/src/browsers/CookieStoreQueryStrategy.ts +99 -0
  33. package/src/browsers/DoSqliteQueryWithTransform.ts +85 -0
  34. package/src/browsers/FirefoxCookieQueryStrategy.ts +12 -7
  35. package/src/browsers/SafariCookieQueryStrategy.ts +3 -0
  36. package/src/browsers/decrypt.ts +118 -0
  37. package/src/browsers/getChromePassword.ts +9 -0
  38. package/src/cli.ts +52 -36
  39. package/src/comboQueryCookieSpec.ts +24 -0
  40. package/src/cookieSpecsFromUrl.ts +26 -0
  41. package/src/execSimple.ts +13 -0
  42. package/src/fetchWithCookies.ts +105 -38
  43. package/src/findAllFiles.ts +26 -54
  44. package/src/getChromeCookie.ts +19 -0
  45. package/src/getCookie.ts +20 -0
  46. package/src/getFirefoxCookie.ts +19 -0
  47. package/src/getGroupedRenderedCookies.ts +11 -24
  48. package/src/getMergedRenderedCookies.ts +12 -0
  49. package/src/global.ts +1 -1
  50. package/src/index.ts +14 -58
  51. package/src/isValidJwt.ts +4 -4
  52. package/src/listChromeProfiles.ts +45 -0
  53. package/src/logger.ts +3 -0
  54. package/src/queryCookies.ts +20 -11
  55. package/src/resultsRendered.ts +6 -3
  56. package/src/util/flatMapAsync.test.ts +55 -0
  57. package/src/util/flatMapAsync.ts +37 -0
  58. package/tsconfig.json +12 -16
  59. package/.github/dependabot.yml +0 -6
  60. package/.prettierrc.json +0 -1
  61. package/src/IsExportedCookie.ts +0 -9
  62. package/src/MemoryCookieStore.ts +0 -5
  63. package/src/browsers/MemoryCookieJarQueryStrategy.ts +0 -53
  64. package/src/doSqliteQuery1.ts +0 -51
  65. package/src/utils.ts +0 -50
@@ -0,0 +1,19 @@
1
+ import CookieSpec from "./CookieSpec";
2
+ import ExportedCookie from "./ExportedCookie";
3
+ import { queryCookies } from "./queryCookies";
4
+ import FirefoxCookieQueryStrategy from "./browsers/FirefoxCookieQueryStrategy";
5
+
6
+ export async function getFirefoxCookie(
7
+ params: CookieSpec
8
+ ): Promise<ExportedCookie | undefined> {
9
+ const cookies: ExportedCookie[] = await queryCookies(
10
+ params,
11
+ new FirefoxCookieQueryStrategy()
12
+ //
13
+ );
14
+ if (Array.isArray(cookies) && cookies.length > 0) {
15
+ return cookies.find((cookie) => cookie != null);
16
+ } else {
17
+ throw new Error("Cookie not found");
18
+ }
19
+ }
@@ -1,32 +1,19 @@
1
- import { queryCookies } from "./queryCookies";
2
- import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
3
1
  import { groupBy } from "lodash";
4
2
  import { resultsRendered } from "./resultsRendered";
5
- import CookieSpec from "./CookieSpec";
3
+ import { MultiCookieSpec } from "./CookieSpec";
6
4
  import ExportedCookie from "./ExportedCookie";
5
+ import { comboQueryCookieSpec } from "./comboQueryCookieSpec";
7
6
 
8
7
  export async function getGroupedRenderedCookies(
9
- //
10
- {
11
- name,
12
- domain,
13
- }: //
14
- CookieSpec
15
- ): //
16
- Promise<string[]> {
17
- const cookies: ExportedCookie[] = await queryCookies(
18
- { name, domain },
19
- new CompositeCookieQueryStrategy()
20
- //
21
- );
22
- if (Array.isArray(cookies) && cookies.length > 0) {
23
- const results: ExportedCookie[] = await queryCookies({ name, domain });
24
- const groupedByFile = groupBy(results, (r) => r.meta?.file);
25
- return Object.keys(groupedByFile).map((file: string) => {
26
- const results: ExportedCookie[] = groupedByFile[file];
27
- return resultsRendered(results);
28
- });
29
- } else {
8
+ cookieSpec: MultiCookieSpec
9
+ ): Promise<string[]> {
10
+ const cookies: ExportedCookie[] = await comboQueryCookieSpec(cookieSpec);
11
+ if (cookies.length == 0) {
30
12
  throw new Error("Cookie not found");
31
13
  }
14
+ const groupedByFile = groupBy(cookies, (r: ExportedCookie) => r.meta?.file);
15
+ return Object.keys(groupedByFile).map((file: string) => {
16
+ const results: ExportedCookie[] = groupedByFile[file];
17
+ return resultsRendered(results);
18
+ });
32
19
  }
@@ -0,0 +1,12 @@
1
+ import { resultsRendered } from "./resultsRendered";
2
+ import { comboQueryCookieSpec } from "./comboQueryCookieSpec";
3
+ import { MultiCookieSpec } from "./CookieSpec";
4
+ import ExportedCookie from "./ExportedCookie";
5
+ import consola from "consola";
6
+
7
+ export async function getMergedRenderedCookies(
8
+ cookieSpec: MultiCookieSpec
9
+ ): Promise<string> {
10
+ const cookies: ExportedCookie[] = await comboQueryCookieSpec(cookieSpec);
11
+ return cookies.length > 0 ? resultsRendered(cookies) : "";
12
+ }
package/src/global.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { merge } from "lodash";
2
2
 
3
3
  export const env: any = {};
4
- merge(env, process.env);
4
+ merge(env, process?.env ?? {});
5
5
  export const HOME: string = env["HOME"];
6
6
  if (!HOME) {
7
7
  throw new Error("HOME environment variable is not set");
package/src/index.ts CHANGED
@@ -1,62 +1,18 @@
1
- #!/usr/bin/env node
2
- // noinspection JSUnusedGlobalSymbols
1
+ #!/usr/bin/env bun run
3
2
 
4
- import { queryCookies } from "./queryCookies";
5
- import FirefoxCookieQueryStrategy from "./browsers/FirefoxCookieQueryStrategy";
6
- import ChromeCookieQueryStrategy from "./browsers/ChromeCookieQueryStrategy";
7
- import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
8
- import CookieSpec from "./CookieSpec";
9
- import ExportedCookie from "./ExportedCookie";
3
+ import { getCookie } from "./getCookie";
4
+ import { getChromeCookie } from "./getChromeCookie";
5
+ import { getFirefoxCookie } from "./getFirefoxCookie";
10
6
  import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
7
+ import { getMergedRenderedCookies } from "./getMergedRenderedCookies";
11
8
  import { fetchWithCookies } from "./fetchWithCookies";
12
9
 
13
- export async function getCookie(
14
- params: CookieSpec
15
- ): Promise<ExportedCookie | undefined> {
16
- const cookies = await queryCookies(
17
- params,
18
- new CompositeCookieQueryStrategy()
19
- //
20
- );
21
- if (Array.isArray(cookies) && cookies.length > 0) {
22
- return cookies.find((cookie) => cookie != null);
23
- } else {
24
- throw new Error("Cookie not found");
25
- }
26
- }
27
-
28
- export async function getFirefoxCookie(
29
- params: CookieSpec
30
- ): Promise<ExportedCookie | undefined> {
31
- const cookies = await queryCookies(
32
- params,
33
- new FirefoxCookieQueryStrategy()
34
- //
35
- );
36
- if (Array.isArray(cookies) && cookies.length > 0) {
37
- return cookies.find((cookie) => cookie != null);
38
- } else {
39
- throw new Error("Cookie not found");
40
- }
41
- }
42
-
43
- export async function getChromeCookie(
44
- params: CookieSpec
45
- ): Promise<ExportedCookie | undefined> {
46
- const cookies = await queryCookies(
47
- params,
48
- new ChromeCookieQueryStrategy()
49
- //
50
- );
51
- if (Array.isArray(cookies) && cookies.length > 0) {
52
- return cookies.find((cookie) => cookie != null);
53
- } else {
54
- throw new Error("Cookie not found");
55
- }
56
- }
57
-
58
- export { getGroupedRenderedCookies, fetchWithCookies };
59
-
60
- export * from "./CookieSpec";
61
- export * from "./CookieRow";
62
- export * from "./ExportedCookie";
10
+ export {
11
+ getCookie,
12
+ getChromeCookie,
13
+ getFirefoxCookie,
14
+ getMergedRenderedCookies,
15
+ getGroupedRenderedCookies,
16
+ fetchWithCookies,
17
+ //
18
+ };
package/src/isValidJwt.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import jsonwebtoken, { JwtPayload } from "jsonwebtoken";
2
- import { env } from "./global";
2
+ import { parsedArgs } from "./argv";
3
3
 
4
- export default function isValidJwt(token: any) {
4
+ export default function isValidJwt(token: string) {
5
5
  try {
6
6
  const result = jsonwebtoken.decode(token, { complete: true });
7
- if (env.VERBOSE) {
8
- console.log(result);
7
+ if (parsedArgs.verbose && result) {
8
+ console.debug(result);
9
9
  }
10
10
  const payload: JwtPayload = result?.payload as JwtPayload;
11
11
  if (payload) {
@@ -0,0 +1,45 @@
1
+ import { sync } from "fast-glob";
2
+ import { chromeApplicationSupport } from "./browsers/ChromeApplicationSupport";
3
+ import { dirname } from "path";
4
+ import { readFile } from "fs/promises";
5
+ import { flatMapAsync } from "./util/flatMapAsync";
6
+ import destr from "destr";
7
+
8
+ export async function listChromeProfilePaths(): Promise<string[]> {
9
+ return sync(`./**/Cookies`, {
10
+ cwd: chromeApplicationSupport,
11
+ absolute: true,
12
+ onlyFiles: true,
13
+ deep: 2,
14
+ }).map((f) => {
15
+ // parent dir
16
+ return dirname(f);
17
+ });
18
+ }
19
+
20
+ export async function listChromeProfiles(): Promise<ChromeProfile[]> {
21
+ const paths = await listChromeProfilePaths();
22
+ return await flatMapAsync(paths, async (p) => {
23
+ const content = await readFile(`${p}/Preferences`, "utf-8");
24
+ return await destr(content);
25
+ });
26
+ }
27
+
28
+ export type ChromeProfileAccountInfo = {
29
+ account_id: string;
30
+ accountcapabilities: any;
31
+ email: string;
32
+ full_name: string;
33
+ gaia: string;
34
+ given_name: string;
35
+ hd: string;
36
+ is_supervised_child: number;
37
+ is_under_advanced_protection: boolean;
38
+ last_downloaded_image_url_with_size: string;
39
+ locale: string;
40
+ picture_url: string;
41
+ };
42
+
43
+ export type ChromeProfile = {
44
+ account_info: ChromeProfileAccountInfo[];
45
+ };
package/src/logger.ts ADDED
@@ -0,0 +1,3 @@
1
+ import consola from "consola";
2
+
3
+ export default consola;
@@ -1,5 +1,5 @@
1
- import { env } from "./global";
2
1
  import { uniqBy } from "lodash";
2
+ import { parsedArgs } from "./argv";
3
3
  import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
4
4
  import CookieQueryStrategy from "./browsers/CookieQueryStrategy";
5
5
  import isValidJwt from "./isValidJwt";
@@ -7,18 +7,27 @@ import CookieSpec from "./CookieSpec";
7
7
  import ExportedCookie from "./ExportedCookie";
8
8
 
9
9
  export async function queryCookies(
10
- { name, domain }: CookieSpec,
10
+ {
11
+ name,
12
+ domain,
13
+ }: //
14
+ CookieSpec,
11
15
  strategy: CookieQueryStrategy = new CompositeCookieQueryStrategy()
12
- ) {
16
+ ): Promise<ExportedCookie[]> {
17
+ //
13
18
  const results: ExportedCookie[] = await strategy.queryCookies(name, domain);
14
- const results1: ExportedCookie[] = uniqBy(results, JSON.stringify);
15
- const jwtCookies = [];
16
- for (const result of results1) {
17
- const value = result.value;
18
- if (isValidJwt(value)) {
19
- jwtCookies.push(result);
19
+ const allCookies: ExportedCookie[] = uniqBy(results, JSON.stringify);
20
+
21
+ if (parsedArgs["require-jwt"]) {
22
+ const jwtCookies = [];
23
+ for (const result of allCookies) {
24
+ const value: string = result.value;
25
+ if (isValidJwt(value)) {
26
+ jwtCookies.push(result);
27
+ }
20
28
  }
29
+ return parsedArgs["single"] ? [jwtCookies[0]] : jwtCookies;
30
+ } else {
31
+ return parsedArgs["single"] ? [allCookies[0]] : allCookies;
21
32
  }
22
- const resultsUniq = env.REQUIRE_JWT ? jwtCookies : results1;
23
- return env.SINGLE ? [resultsUniq[0]] : resultsUniq;
24
33
  }
@@ -1,8 +1,11 @@
1
- import { uniqBy } from "lodash";
1
+ import { orderBy, uniqBy } from "lodash";
2
2
  import ExportedCookie from "./ExportedCookie";
3
3
 
4
4
  export function resultsRendered(results: ExportedCookie[]) {
5
- return uniqBy(results, (r) => r.name)
6
- .map((r) => r.name + "=" + r.value)
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)
7
10
  .join("; ");
8
11
  }
@@ -0,0 +1,55 @@
1
+ import { flatMapAsync } from "./flatMapAsync";
2
+
3
+ describe("flatMapAsync", () => {
4
+ it("should apply async callback to each element, wait for all promises to fulfill and flatten the resulting array", async () => {
5
+ const array = [1, 2, 3];
6
+ const callback = async (value: number) => [value, value * 2];
7
+ const result = await flatMapAsync(array, callback);
8
+ expect(result).toEqual([1, 2, 2, 4, 3, 6]);
9
+ });
10
+
11
+ it("should handle errors with the provided error callback", async () => {
12
+ const array = [1, 2, 3];
13
+ const callback = async (value: number) => {
14
+ if (value === 2) {
15
+ throw new Error("Test error");
16
+ }
17
+ return [value, value * 2];
18
+ };
19
+ const errorCallback = (error: any) => [0];
20
+ const result = await flatMapAsync(array, callback, errorCallback);
21
+ expect(result).toEqual([1, 2, 0, 3, 6]);
22
+ });
23
+
24
+ it("should return an empty array when input array is empty", async () => {
25
+ const array: number[] = [];
26
+ const callback = async (value: number) => [value, value * 2];
27
+ const result = await flatMapAsync(array, callback);
28
+ expect(result).toEqual([]);
29
+ });
30
+
31
+ it("should return an array with single element when input array has one element", async () => {
32
+ const array = [1];
33
+ const callback = async (value: number) => [value, value * 2];
34
+ const result = await flatMapAsync(array, callback);
35
+ expect(result).toEqual([1, 2]);
36
+ });
37
+
38
+ it("should handle null values in the array", async () => {
39
+ const array = [1, null, 3];
40
+ const callback = async (value: number) =>
41
+ value ? [value, value * 2] : [0];
42
+ // @ts-expect-error
43
+ const result = await flatMapAsync(array, callback);
44
+ expect(result).toEqual([1, 2, 0, 3, 6]);
45
+ });
46
+
47
+ it("should handle undefined values in the array", async () => {
48
+ const array = [1, undefined, 3];
49
+ const callback = async (value: number) =>
50
+ value ? [value, value * 2] : [0];
51
+ // @ts-expect-error
52
+ const result = await flatMapAsync(array, callback);
53
+ expect(result).toEqual([1, 2, 0, 3, 6]);
54
+ });
55
+ });
@@ -0,0 +1,37 @@
1
+ // This utility function applies an async callback to each element of the input array (just like Array.prototype.map),
2
+ // waits for all resulting promises to fulfill (similar to Promise.all), and then flattens the resulting array (like Array.prototype.flat).
3
+
4
+ export async function flatMapAsync<T, O>(
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.,
7
+ or?: O[] | ((error: any) => O[] | Promise<O[]>) // An optional callback to handle errors.
8
+ ): Promise<O[]> {
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
+ );
21
+ }
22
+
23
+ // Step 1: Use Array.prototype.map to transform each element of the input array with the provided callback.
24
+ // This will result in an array of promises.
25
+ const ps: Promise<O>[] = array.map(callback) as Promise<O>[];
26
+
27
+ // Step 2: Use Promise.all to wait for all promises in the array to fulfill.
28
+ // This will give us an array of fulfilled promise values.
29
+ const awaitedAll: Awaited<O>[] = await Promise.all(ps);
30
+
31
+ // Step 3: Flatten the array of fulfilled promise values into a single array.
32
+ // Note: The '@ts-ignore' comment is used to suppress TypeScript compiler warnings, as .flat() method might not be recognized
33
+ // as a valid method for an array of Awaited<O> instances. However, this code assumes that the result of Promise.all
34
+ // is indeed an array that can be flattened.
35
+ // @ts-ignore
36
+ return awaitedAll.flat() as O[];
37
+ }
package/tsconfig.json CHANGED
@@ -1,23 +1,19 @@
1
1
  {
2
- "include": [
3
- "src/**.ts",
4
- "src/**.tsx",
5
- "src/**.js",
6
- "src/**.jsx"
7
- ],
2
+ "include": ["src/**.ts", "src/**.tsx", "src/**.js", "src/**.jsx"],
8
3
  "compilerOptions": {
9
4
  "moduleResolution": "node",
10
- "target": "es2021",
11
- "types": [
12
- "node"
13
- ],
14
- "lib": [
15
- "es2015",
16
- "es2017",
17
- "es2021",
18
- "dom"
19
- ],
5
+ "target": "es6",
6
+ "types": ["node"],
7
+ "lib": ["es2015", "es2017", "es2021", "dom"],
20
8
  "strict": true,
9
+ "skipDefaultLibCheck": true,
10
+ "skipLibCheck": true,
21
11
  "allowSyntheticDefaultImports": true,
12
+ "emitDeclarationOnly": true,
13
+ "declaration": true,
14
+ "esModuleInterop": true,
15
+ "module": "commonjs",
16
+ "outDir": "dist",
17
+ "outFile": "dist/types.d.ts"
22
18
  }
23
19
  }
@@ -1,6 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: "npm"
4
- directory: "/"
5
- schedule:
6
- interval: "daily"
package/.prettierrc.json DELETED
@@ -1 +0,0 @@
1
- {}
@@ -1,9 +0,0 @@
1
- import ExportedCookie from "./ExportedCookie";
2
-
3
- export function isExportedCookie(obj: any): obj is ExportedCookie {
4
- return (
5
- obj.domain !== undefined &&
6
- obj.name !== undefined &&
7
- obj.value !== undefined
8
- );
9
- }
@@ -1,5 +0,0 @@
1
- import { CookieJar, MemoryCookieStore } from "tough-cookie";
2
-
3
- export const memoryCookieStore = new MemoryCookieStore();
4
-
5
- export const cookieJar = new CookieJar(memoryCookieStore);
@@ -1,53 +0,0 @@
1
- import ExportedCookie from "../ExportedCookie";
2
- import CookieQueryStrategy from "./CookieQueryStrategy";
3
- import { Cookie } from "tough-cookie";
4
- import CookieSpec from "../CookieSpec";
5
- import { memoryCookieStore } from "../MemoryCookieStore";
6
-
7
- export default class MemoryCookieStoreQueryStrategy
8
- implements CookieQueryStrategy
9
- {
10
- async queryCookies(name: string, domain: string): Promise<ExportedCookie[]> {
11
- if (name == "%" && domain == "%") {
12
- const cookies: Cookie[] = await memoryCookieStore.getAllCookies();
13
- return cookies.map((cookie) => {
14
- return this.#extracted(cookie, { name, domain });
15
- });
16
- }
17
-
18
- const path = "/";
19
-
20
- if (name == "%") {
21
- const cookies: Cookie[] = await memoryCookieStore.findCookies(
22
- domain,
23
- path
24
- );
25
- return cookies.map((cookie) => {
26
- return this.#extracted(cookie, { name, domain });
27
- });
28
- }
29
-
30
- const cookie: Cookie | null = await memoryCookieStore.findCookie(
31
- domain,
32
- path,
33
- name
34
- );
35
-
36
- if (cookie) {
37
- return [this.#extracted(cookie, { name, domain })];
38
- } else {
39
- return [];
40
- }
41
- }
42
-
43
- #extracted(cookie: Cookie, cookieSpec: CookieSpec): ExportedCookie {
44
- return {
45
- domain: cookie.domain ?? cookieSpec.domain,
46
- name: cookie.key ?? cookieSpec.name,
47
- value: cookie.value,
48
- meta: {
49
- file: "memory",
50
- },
51
- };
52
- }
53
- }
@@ -1,51 +0,0 @@
1
- import * as fs from "fs";
2
- import * as sqlite3 from "sqlite3";
3
- import CookieRow from "./CookieRow";
4
- import { merge } from "lodash";
5
-
6
- interface DoSqliteQuery1Params {
7
- file: string;
8
- sql: string;
9
- rowTransform: (row: any) => CookieRow;
10
- }
11
-
12
- export async function doSqliteQuery1({
13
- file,
14
- sql,
15
- rowTransform,
16
- }: DoSqliteQuery1Params): Promise<CookieRow[]> {
17
- if (!file || (file && !fs.existsSync(file))) {
18
- throw new Error(`doSqliteQuery1: file ${file} does not exist`);
19
- }
20
- const db = new sqlite3.Database(file);
21
- return new Promise((resolve, reject) => {
22
- db.all(sql, (err: Error, rows: any[]) => {
23
- if (err) {
24
- reject(err);
25
- return;
26
- }
27
- const rows1: any[] = rows;
28
- if (rows1 == null || rows1.length === 0) {
29
- resolve([]);
30
- return;
31
- }
32
- if (Array.isArray(rows1)) {
33
- const cookieRows: CookieRow[] = rows1.map((row: any) => {
34
- const newVar = {
35
- meta: {
36
- file: file,
37
- },
38
- };
39
- const cookieRow: CookieRow = rowTransform(row);
40
- return merge(newVar, cookieRow);
41
- });
42
- resolve(cookieRows);
43
- return;
44
- }
45
- if (process.env.VERBOSE) {
46
- console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
47
- }
48
- resolve([rows1]);
49
- });
50
- });
51
- }
package/src/utils.ts DELETED
@@ -1,50 +0,0 @@
1
- // noinspection JSUnusedGlobalSymbols
2
-
3
- import { exec, ExecException } from "child_process";
4
-
5
- export async function execSimple(command: string): Promise<string> {
6
- return new Promise((resolve, reject) => {
7
- exec(
8
- command,
9
- { encoding: "binary", maxBuffer: 5 * 1024 },
10
- (error: ExecException | null, stdout: string, stderr: string) => {
11
- if (error) {
12
- reject(error);
13
- return;
14
- }
15
- if (stderr) {
16
- reject(error);
17
- return;
18
- }
19
- if (stdout) {
20
- resolve(stdout.trim());
21
- }
22
- }
23
- );
24
- });
25
- }
26
-
27
- export function toStringOrNull(result: any) {
28
- if (result == null) {
29
- return null;
30
- }
31
- if (process.env.VERBOSE) {
32
- console.log("result", result);
33
- }
34
- if (typeof result === "string" && result.length > 0) {
35
- return result;
36
- }
37
- if (result.slice && result.toString) {
38
- // noinspection JSCheckFunctionSignatures
39
- return result.toString("utf8");
40
- }
41
- return null;
42
- }
43
-
44
- export function invalidString(input: any): boolean {
45
- return typeof input !== "string" || input.length === 0;
46
- }
47
-
48
- export function validString(input: any): input is string {
49
- return typeof input == "string" && input.length > 0;
50
- }