@mherod/get-cookie 2.0.0-beta.1 → 2.0.0-beta.4

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 (35) hide show
  1. package/.idea/codeStyles/Project.xml +59 -0
  2. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  3. package/.idea/get-cookie.iml +1 -0
  4. package/.prettierrc.json +1 -0
  5. package/dist/cli.js +1 -1
  6. package/dist/cli.js.map +1 -1
  7. package/dist/index.js +3 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/main.js +196 -220
  10. package/dist/main.js.map +1 -1
  11. package/dist/module.js +466 -0
  12. package/dist/module.js.map +1 -0
  13. package/dist/types.d.ts +25 -0
  14. package/dist/types.d.ts.map +1 -0
  15. package/package.json +27 -12
  16. package/src/CookieRow.ts +21 -0
  17. package/src/argv.ts +1 -0
  18. package/src/browsers/{AbstractCookieQueryStrategy.js → AbstractCookieQueryStrategy.ts} +3 -1
  19. package/src/browsers/ChromeCookieQueryStrategy.ts +256 -0
  20. package/src/browsers/{CompositeCookieQueryStrategy.js → CompositeCookieQueryStrategy.ts} +5 -2
  21. package/src/browsers/{FirefoxCookieQueryStrategy.js → FirefoxCookieQueryStrategy.ts} +28 -13
  22. package/src/browsers/{SafariCookieQueryStrategy.js → SafariCookieQueryStrategy.ts} +0 -0
  23. package/src/cli.ts +85 -0
  24. package/src/doSqliteQuery1.ts +47 -0
  25. package/src/{findAllFiles.js → findAllFiles.ts} +15 -20
  26. package/src/{global.js → global.ts} +2 -2
  27. package/src/{index.js → index.ts} +3 -8
  28. package/src/{isValidJwt.js → isValidJwt.ts} +1 -4
  29. package/src/queryCookies.ts +29 -0
  30. package/src/utils.ts +118 -0
  31. package/tsconfig.json +23 -0
  32. package/src/browsers/ChromeCookieQueryStrategy.js +0 -263
  33. package/src/cli.js +0 -70
  34. package/src/queryCookies.js +0 -28
  35. package/src/utils.js +0 -181
package/src/cli.js DELETED
@@ -1,70 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { version } from "../package.json";
4
- import { env } from "./global";
5
- import { queryCookies } from "./queryCookies";
6
-
7
- const argv = process.argv;
8
-
9
- async function cliQueryCookies(name, domain) {
10
- try {
11
- const results = await queryCookies({ name, domain });
12
- if (results.length > 0) {
13
- for (const result of results) {
14
- console.log(result);
15
- }
16
- } else {
17
- console.error("No results");
18
- }
19
- } catch (e) {
20
- console.error(e);
21
- }
22
- }
23
-
24
- if (argv && argv.length > 2) {
25
- if (argv.includes("--version") || argv.includes("-v")) {
26
- console.log(version);
27
- return;
28
- }
29
-
30
- const name = argv[2];
31
-
32
- let domain;
33
- if (argv[3] != null && argv[3].indexOf(".") > -1) {
34
- domain = argv[3];
35
- } else {
36
- domain = "%";
37
- }
38
-
39
- const tru = `${true}`;
40
-
41
- if (argv.includes("--require-jwt")) {
42
- env.REQUIRE_JWT = tru;
43
- }
44
- if (argv.includes("--verbose")) {
45
- env.VERBOSE = tru;
46
- }
47
- if (argv.includes("--chrome-only")) {
48
- env.CHROME_ONLY = tru;
49
- }
50
- if (argv.includes("--firefox-only")) {
51
- env.FIREFOX_ONLY = tru;
52
- }
53
- if (argv.includes("--ignore-expired")) {
54
- env.IGNORE_EXPIRED = tru;
55
- }
56
-
57
- if (argv.includes("--single")) {
58
- env.SINGLE = tru;
59
- }
60
-
61
- if (env.VERBOSE) {
62
- console.log("Verbose mode", argv);
63
- }
64
-
65
- cliQueryCookies(name, domain)
66
- .then(() => {
67
- //
68
- })
69
- .catch(console.error);
70
- }
@@ -1,28 +0,0 @@
1
- import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
2
- import { uniq } from "lodash";
3
- import { env } from "./global";
4
- import isValidJwt from "./isValidJwt";
5
-
6
- export async function queryCookies(
7
- { name, domain },
8
- strategy = new CompositeCookieQueryStrategy()
9
- ) {
10
- const results = await strategy.queryCookies(name, domain);
11
- const results1 = uniq(results).map((cookie) => {
12
- return {
13
- name: name,
14
- domain: domain,
15
- value: cookie,
16
- };
17
- });
18
- const jwtCookies = [];
19
- for (const result of results1) {
20
- const value = result.value;
21
- if (isValidJwt(value)) {
22
- jwtCookies.push(result);
23
- }
24
- }
25
- const results2 = env.REQUIRE_JWT ? jwtCookies : results1;
26
- const resultsUniq = uniq(results2).map((cookie) => cookie.value);
27
- return env.SINGLE ? [resultsUniq[0]] : resultsUniq;
28
- }
package/src/utils.js DELETED
@@ -1,181 +0,0 @@
1
- // noinspection JSUnusedGlobalSymbols
2
-
3
- import { exec } from "child_process";
4
-
5
- import fs from "fs";
6
-
7
- export async function execSimple(command) {
8
- if (typeof command !== "string") {
9
- throw new TypeError("execSimple: command must be a string");
10
- }
11
- if (process.env.VERBOSE) {
12
- console.log(command);
13
- }
14
- return new Promise((resolve, reject) => {
15
- exec(
16
- command,
17
- { encoding: "binary", maxBuffer: 5 * 1024 },
18
- (error, stdout, stderr) => {
19
- if (error) {
20
- reject(error);
21
- return;
22
- }
23
- if (stderr) {
24
- reject(error);
25
- return;
26
- }
27
- if (stdout) {
28
- resolve(stdout.toString("utf8").trim());
29
- }
30
- }
31
- );
32
- });
33
- }
34
-
35
- export async function execAsBuffer(command) {
36
- if (typeof command !== "string") {
37
- throw new TypeError("execAsBuffer: command must be a string");
38
- }
39
- if (process.env.VERBOSE) {
40
- console.log(command);
41
- }
42
- return await new Promise((resolve, reject) => {
43
- exec(
44
- command,
45
- { encoding: "binary", maxBuffer: 5 * 1024 },
46
- (error, stdout, stderr) => {
47
- if (error) {
48
- reject(error);
49
- return;
50
- }
51
- if (stderr) {
52
- reject(error);
53
- return;
54
- }
55
- let stdoutAsBuffer = stdout;
56
- if (typeof stdoutAsBuffer === "string" && stdoutAsBuffer.length > 0) {
57
- // noinspection JSCheckFunctionSignatures
58
- stdoutAsBuffer = Buffer.from(stdoutAsBuffer, "binary").slice(0, -1);
59
- }
60
- if (stdoutAsBuffer && stdoutAsBuffer.length > 0) {
61
- resolve(stdoutAsBuffer);
62
- }
63
- }
64
- );
65
- });
66
- }
67
-
68
- export function toStringValue(r) {
69
- if (process.env.VERBOSE) {
70
- console.log("Printing value", r);
71
- }
72
- if (r) {
73
- if (typeof r === "string") {
74
- return r;
75
- } else if (r.toString) {
76
- // noinspection JSCheckFunctionSignatures
77
- return r.toString("utf8");
78
- }
79
- }
80
- }
81
-
82
- export function printStringValue(r) {
83
- if (process.env.VERBOSE) {
84
- console.log("Printing value", r);
85
- }
86
- if (r) {
87
- if (typeof r === "string") {
88
- console.log(r);
89
- } else if (r.toString) {
90
- // noinspection JSCheckFunctionSignatures
91
- console.log(r.toString("utf8"));
92
- }
93
- }
94
- }
95
-
96
- /**
97
- *
98
- * @param result
99
- * @returns {string|null}
100
- */
101
- export function toStringOrNull(result) {
102
- if (result == null) {
103
- return null;
104
- }
105
- if (process.env.VERBOSE) {
106
- console.log("result", result);
107
- }
108
- if (typeof result === "string" && result.length > 0) {
109
- return result;
110
- }
111
- if (result.slice && result.toString) {
112
- // noinspection JSCheckFunctionSignatures
113
- return result.toString("utf8");
114
- }
115
- return null;
116
- }
117
-
118
- /**
119
- *
120
- * @param {string} file
121
- * @param {string} sql
122
- * @returns {Promise<Buffer[]>}
123
- */
124
- export async function doSqliteQuery1(file, sql) {
125
- if (typeof sql !== "string") {
126
- throw new TypeError("doSqliteQuery1: sql must be a string");
127
- }
128
- if (typeof file !== "string") {
129
- throw new TypeError("doSqliteQuery1: file must be a string");
130
- }
131
- if (!fs.existsSync(file)) {
132
- throw new Error(`doSqliteQuery1: file ${file} does not exist`);
133
- }
134
- if (process.env.VERBOSE) {
135
- console.log(`doSqliteQuery1: file ${file}`);
136
- console.log(`doSqliteQuery1: sql ${sql}`);
137
- }
138
- const sqlite3 = require("sqlite3");
139
- const db = new sqlite3.Database(file);
140
- return new Promise((resolve, reject) => {
141
- db.all(sql, (err, rows) => {
142
- if (err) {
143
- if (process.env.VERBOSE) {
144
- console.log(`doSqliteQuery1: error ${err}`);
145
- }
146
- reject(err);
147
- return;
148
- }
149
- const rows1 = rows;
150
- if (rows1 == null || rows1.length === 0) {
151
- if (process.env.VERBOSE) {
152
- console.log(`doSqliteQuery1: no rows`);
153
- }
154
- resolve([]);
155
- return;
156
- }
157
- if (Array.isArray(rows1)) {
158
- if (process.env.VERBOSE) {
159
- console.log(`doSqliteQuery1: ${rows1.length} rows`);
160
- }
161
- // noinspection JSCheckFunctionSignatures
162
- const buffers = rows1
163
- .flatMap((row) => Object.values(row))
164
- .map((v) => Buffer.from(v, "binary"));
165
- if (process.env.VERBOSE) {
166
- console.log(`doSqliteQuery1: ${buffers.length} buffers`);
167
- }
168
- resolve(buffers);
169
- return;
170
- }
171
- if (process.env.VERBOSE) {
172
- console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
173
- }
174
- resolve([rows1]);
175
- });
176
- });
177
- }
178
-
179
- export function invalidString(input) {
180
- return typeof input !== "string" || input.length === 0;
181
- }