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

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/dist/main.js CHANGED
@@ -17,7 +17,7 @@ function $parcel$interopDefault(a) {
17
17
  $parcel$export(module.exports, "getCookie", () => $af7abeb0794bd6fa$export$4be65e66cfa2648a);
18
18
  $parcel$export(module.exports, "getFirefoxCookie", () => $af7abeb0794bd6fa$export$c44c5fdef43f0941);
19
19
  $parcel$export(module.exports, "getChromeCookie", () => $af7abeb0794bd6fa$export$e5637297e9eb6f2e);
20
- class $36bba8acd7b702be$export$2e2bcd8739ae039 {
20
+ class $503d2a3d296fcf21$export$2e2bcd8739ae039 {
21
21
  async queryCookies(name, domain) {
22
22
  if (process.env.NODE_ENV === "development") console.log("queryCookie", name, domain);
23
23
  return [];
@@ -26,9 +26,7 @@ class $36bba8acd7b702be$export$2e2bcd8739ae039 {
26
26
 
27
27
 
28
28
 
29
-
30
- async function $c0cdc003fbf917f0$export$8d71c74f97c0202e(command) {
31
- if (typeof command !== "string") throw new TypeError("execSimple: command must be a string");
29
+ async function $25b78d6746d4ad48$export$8d71c74f97c0202e(command) {
32
30
  if (process.env.VERBOSE) console.log(command);
33
31
  return new Promise((resolve, reject)=>{
34
32
  (0, $bU6Ve$child_process.exec)(command, {
@@ -43,34 +41,11 @@ async function $c0cdc003fbf917f0$export$8d71c74f97c0202e(command) {
43
41
  reject(error);
44
42
  return;
45
43
  }
46
- if (stdout) resolve(stdout.toString("utf8").trim());
47
- });
48
- });
49
- }
50
- async function $c0cdc003fbf917f0$export$1704cc27537f7088(command) {
51
- if (typeof command !== "string") throw new TypeError("execAsBuffer: command must be a string");
52
- if (process.env.VERBOSE) console.log(command);
53
- return await new Promise((resolve, reject)=>{
54
- (0, $bU6Ve$child_process.exec)(command, {
55
- encoding: "binary",
56
- maxBuffer: 5120
57
- }, (error, stdout, stderr)=>{
58
- if (error) {
59
- reject(error);
60
- return;
61
- }
62
- if (stderr) {
63
- reject(error);
64
- return;
65
- }
66
- let stdoutAsBuffer = stdout;
67
- if (typeof stdoutAsBuffer === "string" && stdoutAsBuffer.length > 0) // noinspection JSCheckFunctionSignatures
68
- stdoutAsBuffer = Buffer.from(stdoutAsBuffer, "binary").slice(0, -1);
69
- if (stdoutAsBuffer && stdoutAsBuffer.length > 0) resolve(stdoutAsBuffer);
44
+ if (stdout) resolve(stdout.trim());
70
45
  });
71
46
  });
72
47
  }
73
- function $c0cdc003fbf917f0$export$33d3adc27420eed5(r) {
48
+ function $25b78d6746d4ad48$export$33d3adc27420eed5(r) {
74
49
  if (process.env.VERBOSE) console.log("Printing value", r);
75
50
  if (r) {
76
51
  if (typeof r === "string") return r;
@@ -78,7 +53,7 @@ function $c0cdc003fbf917f0$export$33d3adc27420eed5(r) {
78
53
  return r.toString("utf8");
79
54
  }
80
55
  }
81
- function $c0cdc003fbf917f0$export$1ed1ce2ec2b4f5a3(r) {
56
+ function $25b78d6746d4ad48$export$1ed1ce2ec2b4f5a3(r) {
82
57
  if (process.env.VERBOSE) console.log("Printing value", r);
83
58
  if (r) {
84
59
  if (typeof r === "string") console.log(r);
@@ -86,7 +61,7 @@ function $c0cdc003fbf917f0$export$1ed1ce2ec2b4f5a3(r) {
86
61
  console.log(r.toString("utf8"));
87
62
  }
88
63
  }
89
- function $c0cdc003fbf917f0$export$d53bf2de587a369(result) {
64
+ function $25b78d6746d4ad48$export$d53bf2de587a369(result) {
90
65
  if (result == null) return null;
91
66
  if (process.env.VERBOSE) console.log("result", result);
92
67
  if (typeof result === "string" && result.length > 0) return result;
@@ -94,98 +69,61 @@ function $c0cdc003fbf917f0$export$d53bf2de587a369(result) {
94
69
  return result.toString("utf8");
95
70
  return null;
96
71
  }
97
-
98
- async function $c0cdc003fbf917f0$export$f19f611d1fa7c6f3(file, sql) {
99
- if (typeof sql !== "string") throw new TypeError("doSqliteQuery1: sql must be a string");
100
- if (typeof file !== "string") throw new TypeError("doSqliteQuery1: file must be a string");
101
- if (!(0, ($parcel$interopDefault($bU6Ve$fs))).existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
102
- if (process.env.VERBOSE) {
103
- console.log(`doSqliteQuery1: file ${file}`);
104
- console.log(`doSqliteQuery1: sql ${sql}`);
105
- }
106
- const sqlite3 = $bU6Ve$sqlite3;
107
- const db = new sqlite3.Database(file);
108
- return new Promise((resolve, reject)=>{
109
- db.all(sql, (err, rows)=>{
110
- if (err) {
111
- if (process.env.VERBOSE) console.log(`doSqliteQuery1: error ${err}`);
112
- reject(err);
113
- return;
114
- }
115
- const rows1 = rows;
116
- if (rows1 == null || rows1.length === 0) {
117
- if (process.env.VERBOSE) console.log(`doSqliteQuery1: no rows`);
118
- resolve([]);
119
- return;
120
- }
121
- if (Array.isArray(rows1)) {
122
- if (process.env.VERBOSE) console.log(`doSqliteQuery1: ${rows1.length} rows`);
123
- // noinspection JSCheckFunctionSignatures
124
- const buffers = rows1.flatMap((row)=>Object.values(row)).map((v)=>Buffer.from(v, "binary"));
125
- if (process.env.VERBOSE) console.log(`doSqliteQuery1: ${buffers.length} buffers`);
126
- resolve(buffers);
127
- return;
128
- }
129
- if (process.env.VERBOSE) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
130
- resolve([
131
- rows1
132
- ]);
133
- });
134
- });
135
- }
136
- function $c0cdc003fbf917f0$export$99ce3e33a555daf1(input) {
72
+ function $25b78d6746d4ad48$export$99ce3e33a555daf1(input) {
137
73
  return typeof input !== "string" || input.length === 0;
138
74
  }
75
+ function $25b78d6746d4ad48$export$5348b46700dd771c(input) {
76
+ return typeof input == "string" && input.length > 0;
77
+ }
139
78
 
140
79
 
141
80
 
142
- var $fa5ed5287f8fdf72$require$merge = $bU6Ve$lodash.merge;
143
- const $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3 = {};
144
- $fa5ed5287f8fdf72$require$merge($fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3, process.env);
145
- const $fa5ed5287f8fdf72$export$a7c5707626fc90f = $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3["HOME"];
146
- if (!$fa5ed5287f8fdf72$export$a7c5707626fc90f) throw new Error("HOME environment variable is not set");
81
+ var $fac425c10fbbada5$require$merge = $bU6Ve$lodash.merge;
82
+ const $fac425c10fbbada5$export$a7b6bc01c63cdfc3 = {};
83
+ $fac425c10fbbada5$require$merge($fac425c10fbbada5$export$a7b6bc01c63cdfc3, process.env);
84
+ const $fac425c10fbbada5$export$a7c5707626fc90f = $fac425c10fbbada5$export$a7b6bc01c63cdfc3["HOME"];
85
+ if (!$fac425c10fbbada5$export$a7c5707626fc90f) throw new Error("HOME environment variable is not set");
147
86
 
148
87
 
149
88
 
150
89
 
151
90
 
152
- async function $d6c2e79f3cdd498d$export$2c9faf86071156ae({ path: path , name: name , maxDepth: maxDepth = 2 }) {
91
+ async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: name , maxDepth: maxDepth = 2 }) {
153
92
  if (typeof path !== "string") throw new Error("path must be a string");
154
93
  if (typeof name !== "string") throw new Error("name must be a string");
155
94
  const rootSegments = path.split("/").length;
156
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Searching for ${name} in ${path}`);
95
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Searching for ${name} in ${path}`);
157
96
  const files = [];
158
97
  let readdirSync;
159
98
  try {
160
- readdirSync = (0, ($parcel$interopDefault($bU6Ve$fs))).readdirSync(path);
99
+ readdirSync = $bU6Ve$fs.readdirSync(path);
161
100
  } catch (e) {
162
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Error reading ${path}`, e);
163
- return files;
101
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Error reading ${path}`, e);
102
+ return [];
164
103
  }
165
104
  for (const file of readdirSync){
166
105
  const filePath = path + "/" + file;
167
106
  let stat;
168
107
  try {
169
- stat = (0, ($parcel$interopDefault($bU6Ve$fs))).statSync(filePath);
108
+ stat = $bU6Ve$fs.statSync(filePath);
170
109
  } catch (e1) {
171
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error(`Error getting stat for ${filePath}`, e1);
110
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.error(`Error getting stat for ${filePath}`, e1);
172
111
  continue;
173
112
  }
174
113
  if (stat.isDirectory()) {
175
114
  if (filePath.split("/").length < rootSegments + maxDepth) try {
176
- const subFiles = await $d6c2e79f3cdd498d$export$2c9faf86071156ae({
115
+ const subFiles = await $e62c2c56eb720f29$export$2c9faf86071156ae({
177
116
  path: filePath,
178
117
  name: name,
179
- rootSegments: rootSegments,
180
118
  maxDepth: 2
181
119
  });
182
120
  files.push(...subFiles);
183
121
  } catch (e2) {
184
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.error(e2);
122
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.error(e2);
185
123
  }
186
124
  } else if (file === name) files.push(filePath);
187
125
  }
188
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) {
126
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) {
189
127
  if (files.length > 0) {
190
128
  console.log(`Found ${files.length} ${name} files`);
191
129
  console.log(files);
@@ -197,111 +135,148 @@ async function $d6c2e79f3cdd498d$export$2c9faf86071156ae({ path: path , name: na
197
135
 
198
136
 
199
137
 
200
- class $1c57ad353fa3519e$export$2e2bcd8739ae039 extends (0, $36bba8acd7b702be$export$2e2bcd8739ae039) {
138
+ function $3d7e27b54f670f46$export$bc926c43858bd3cb(obj) {
139
+ return obj.domain !== undefined && obj.name !== undefined && obj.value !== undefined;
140
+ }
141
+ function $3d7e27b54f670f46$export$963c8d651337e4a4(obj) {
142
+ return obj.domain !== undefined && obj.name !== undefined && obj.value !== undefined;
143
+ }
144
+
145
+
146
+
147
+
148
+ async function $a085b524d8ee9fce$export$f19f611d1fa7c6f3(file, sql) {
149
+ if (!$bU6Ve$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
150
+ const db = new $bU6Ve$sqlite3.Database(file);
151
+ return new Promise((resolve, reject)=>{
152
+ db.all(sql, (err, rows)=>{
153
+ if (err) {
154
+ if (process.env.VERBOSE) console.log(`doSqliteQuery1: error ${err}`);
155
+ reject(err);
156
+ return;
157
+ }
158
+ const rows1 = rows;
159
+ if (rows1 == null || rows1.length === 0) {
160
+ if (process.env.VERBOSE) console.log(`doSqliteQuery1: no rows`);
161
+ resolve([]);
162
+ return;
163
+ }
164
+ if (Array.isArray(rows1)) {
165
+ const cookieRows = rows1.map((row)=>{
166
+ return {
167
+ domain: row["host_key"],
168
+ name: row["name"],
169
+ value: row["encrypted_value"],
170
+ meta: {
171
+ file: file
172
+ }
173
+ };
174
+ });
175
+ resolve(cookieRows);
176
+ return;
177
+ }
178
+ if (process.env.VERBOSE) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
179
+ resolve([
180
+ rows1
181
+ ]);
182
+ });
183
+ });
184
+ }
185
+
186
+
187
+
188
+ class $269fe42bfd555305$export$2e2bcd8739ae039 extends (0, $503d2a3d296fcf21$export$2e2bcd8739ae039) {
201
189
  async queryCookies(name, domain) {
202
190
  if (process.platform !== "darwin") throw new Error("This only works on macOS");
203
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).FIREFOX_ONLY) return [];
204
- const cookies = await $1c57ad353fa3519e$var$getChromeCookies({
191
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).FIREFOX_ONLY) return [];
192
+ return $269fe42bfd555305$var$getChromeCookies({
193
+ requireJwt: false,
205
194
  name: name,
206
195
  domain: domain
207
196
  });
208
- return cookies.map((0, $c0cdc003fbf917f0$export$33d3adc27420eed5));
209
197
  }
210
198
  }
211
- async function $1c57ad353fa3519e$var$getPromise1(name, domain, file) {
199
+ async function $269fe42bfd555305$var$getPromise1(name, domain, file) {
212
200
  try {
213
- return await $1c57ad353fa3519e$var$getEncryptedChromeCookie({
201
+ return await $269fe42bfd555305$var$getEncryptedChromeCookie({
214
202
  name: name,
215
203
  domain: domain,
216
204
  file: file
217
205
  });
218
206
  } catch (e) {
219
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error getting encrypted cookie", e);
207
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error getting encrypted cookie", e);
220
208
  return [];
221
209
  }
222
210
  }
223
- async function $1c57ad353fa3519e$var$getPromise(name, domain) {
211
+ async function $269fe42bfd555305$var$getPromise(name, domain) {
224
212
  try {
225
- const files = await (0, $d6c2e79f3cdd498d$export$2c9faf86071156ae)({
226
- path: $1c57ad353fa3519e$var$chromeLocal,
213
+ const files = await (0, $e62c2c56eb720f29$export$2c9faf86071156ae)({
214
+ path: $269fe42bfd555305$var$chromeLocal,
227
215
  name: "Cookies"
228
216
  });
229
- const promises = files.map((file)=>$1c57ad353fa3519e$var$getPromise1(name, domain, file));
217
+ const promises = files.map((file)=>$269fe42bfd555305$var$getPromise1(name, domain, file));
230
218
  const results1 = await Promise.all(promises);
231
- const results2 = results1.flat();
232
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("getEncryptedChromeCookie results", results2);
233
- return results2.filter((result)=>result);
219
+ return results1.flat().filter((0, $3d7e27b54f670f46$export$bc926c43858bd3cb));
234
220
  } catch (error) {
235
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("error", error);
221
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("error", error);
236
222
  return [];
237
223
  }
238
224
  }
239
- /**
240
- *
241
- * @param {string|undefined} name
242
- * @param {string} domain
243
- * @param {boolean} requireJwt
244
- * @returns {Promise<[string]>}
245
- */ async function $1c57ad353fa3519e$var$getChromeCookies({ name: name , domain: domain = "%" , requireJwt: requireJwt = false }) {
246
- if ((0, $c0cdc003fbf917f0$export$99ce3e33a555daf1)(name)) throw new Error("name must be a string");
247
- if ((0, $c0cdc003fbf917f0$export$99ce3e33a555daf1)(domain)) throw new Error("domain must be a string");
248
- const encryptedDataItems = await $1c57ad353fa3519e$var$getPromise(name, domain);
249
- const password = await $1c57ad353fa3519e$var$getChromePassword();
250
- const decrypted = encryptedDataItems.filter((encryptedData)=>{
251
- return encryptedData != null && encryptedData.length > 0;
252
- }).map(async (encryptedData)=>{
253
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Received encrypted", encryptedData);
254
- let d;
255
- try {
256
- d = await $1c57ad353fa3519e$var$decrypt(password, encryptedData);
257
- } catch (e) {
258
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error decrypting cookie", e);
259
- return null;
260
- }
261
- if (d) {
262
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Decrypted", d);
263
- return d;
264
- }
265
- return null;
225
+ async function $269fe42bfd555305$var$decryptValue(password, encryptedValue) {
226
+ let d;
227
+ try {
228
+ d = await $269fe42bfd555305$var$decrypt(password, encryptedValue);
229
+ } catch (e) {
230
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error decrypting cookie", e);
231
+ d = null;
232
+ }
233
+ return d ?? encryptedValue.toString("utf-8");
234
+ }
235
+ async function $269fe42bfd555305$var$getChromeCookies({ name: name , domain: domain = "%" , requireJwt: requireJwt = false }) {
236
+ const encryptedDataItems = await $269fe42bfd555305$var$getPromise(name, domain);
237
+ const password = await $269fe42bfd555305$var$getChromePassword();
238
+ const decrypted = encryptedDataItems.filter(({ value: value })=>value != null && value.length > 0).map(async (cookieRow)=>{
239
+ const encryptedValue = cookieRow.value;
240
+ const decryptedValue = await $269fe42bfd555305$var$decryptValue(password, encryptedValue);
241
+ const meta = {};
242
+ (0, $bU6Ve$lodash.merge)(meta, cookieRow.meta ?? {});
243
+ return {
244
+ domain: cookieRow.domain,
245
+ name: cookieRow.name,
246
+ value: decryptedValue,
247
+ meta: meta
248
+ };
266
249
  });
267
- const results = await Promise.all(decrypted);
268
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("results", results);
269
- return results.map((0, $c0cdc003fbf917f0$export$d53bf2de587a369));
250
+ const results = (await Promise.all(decrypted)).filter((0, $3d7e27b54f670f46$export$963c8d651337e4a4));
251
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("results", results);
252
+ return results;
270
253
  }
271
- const $1c57ad353fa3519e$var$chromeLocal = $bU6Ve$path.join((0, $fa5ed5287f8fdf72$export$a7c5707626fc90f), "Library", "Application Support", "Google", "Chrome");
272
- async function $1c57ad353fa3519e$var$getEncryptedChromeCookie({ name: name , domain: domain , file: file = $bU6Ve$path.join($1c57ad353fa3519e$var$chromeLocal, "Default", "Cookies") , }) {
273
- if (name && typeof name !== "string") throw new Error("name must be a string");
274
- if (domain && typeof domain !== "string") throw new Error("domain must be a string");
275
- if (file && typeof file !== "string") throw new Error("file must be a string");
254
+ const $269fe42bfd555305$var$chromeLocal = $bU6Ve$path.join((0, $fac425c10fbbada5$export$a7c5707626fc90f), "Library", "Application Support", "Google", "Chrome");
255
+ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , domain: domain , file: file = $bU6Ve$path.join($269fe42bfd555305$var$chromeLocal, "Default", "Cookies") }) {
276
256
  if (!(0, $bU6Ve$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
277
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) {
257
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) {
278
258
  const s = file.split("/").slice(-3).join("/");
279
259
  console.log(`Trying Chrome (at ${s}) cookie ${name} for domain ${domain}`);
280
260
  }
281
261
  let sql;
282
- sql = `SELECT encrypted_value FROM cookies`;
283
- if (typeof name === "string" || typeof domain === "string") {
262
+ sql = `SELECT encrypted_value, name, host_key FROM cookies`;
263
+ const wildcardRegexp = /^([*%])$/i;
264
+ const specifiedName = name.match(wildcardRegexp) == null;
265
+ const specifiedDomain = domain.match(wildcardRegexp) == null;
266
+ if (specifiedName || specifiedDomain) {
284
267
  sql += ` WHERE `;
285
- if (typeof name === "string") {
268
+ if (specifiedName) {
286
269
  sql += `name = '${name}'`;
287
- if (typeof domain === "string") sql += ` AND `;
270
+ if (specifiedDomain) sql += ` AND `;
288
271
  }
289
- if (typeof domain === "string") sql += `host_key LIKE '${domain}';`;
272
+ if (specifiedDomain) sql += `host_key LIKE '${domain}';`;
290
273
  }
291
- return (0, $c0cdc003fbf917f0$export$f19f611d1fa7c6f3)(file, sql);
274
+ return (0, $a085b524d8ee9fce$export$f19f611d1fa7c6f3)(file, sql);
292
275
  }
293
- /**
294
- *
295
- * @returns {Promise<string>}
296
- */ async function $1c57ad353fa3519e$var$getChromePassword() {
297
- return (0, $c0cdc003fbf917f0$export$8d71c74f97c0202e)('security find-generic-password -w -s "Chrome Safe Storage"');
276
+ async function $269fe42bfd555305$var$getChromePassword() {
277
+ return (0, $25b78d6746d4ad48$export$8d71c74f97c0202e)('security find-generic-password -w -s "Chrome Safe Storage"');
298
278
  }
299
- /**
300
- *
301
- * @param {string} password
302
- * @param {Buffer} encryptedData
303
- * @returns {Promise<string>}
304
- */ async function $1c57ad353fa3519e$var$decrypt(password, encryptedData) {
279
+ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
305
280
  if (typeof password !== "string") throw new Error("password must be a string: " + password);
306
281
  let encryptedData1;
307
282
  encryptedData1 = encryptedData;
@@ -309,30 +284,31 @@ async function $1c57ad353fa3519e$var$getEncryptedChromeCookie({ name: name , dom
309
284
  if (!(encryptedData1 instanceof Buffer)) {
310
285
  if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {
311
286
  [encryptedData1] = encryptedData1;
312
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`encryptedData is an array of buffers, selected first: ${encryptedData1}`);
287
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`encryptedData is an array of buffers, selected first: ${encryptedData1}`);
313
288
  } else throw new Error("encryptedData must be a Buffer: " + encryptedData1);
314
289
  encryptedData1 = Buffer.from(encryptedData1);
315
290
  }
316
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying to decrypt with password ${password}`);
291
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying to decrypt with password ${password}`);
317
292
  return new Promise((resolve, reject)=>{
318
- (0, ($parcel$interopDefault($bU6Ve$crypto))).pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer)=>{
293
+ $bU6Ve$crypto.pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer)=>{
319
294
  try {
320
295
  if (error) {
321
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2", error);
296
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2", error);
322
297
  reject(error);
323
298
  return;
324
299
  }
325
300
  if (buffer.length !== 16) {
326
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, buffer length is not 16", buffer.length);
301
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, buffer length is not 16", buffer.length);
327
302
  reject(new Error("Buffer length is not 16"));
328
303
  return;
329
304
  }
330
- const iv = new Buffer.from(new Array(17).join(" "), "binary");
331
- const decipher = (0, ($parcel$interopDefault($bU6Ve$crypto))).createDecipheriv("aes-128-cbc", buffer, iv);
305
+ const str = new Array(17).join(" ");
306
+ const iv = Buffer.from(str, "binary");
307
+ const decipher = $bU6Ve$crypto.createDecipheriv("aes-128-cbc", buffer, iv);
332
308
  decipher.setAutoPadding(false);
333
309
  if (encryptedData1 && encryptedData1.slice) encryptedData1 = encryptedData1.slice(3);
334
310
  if (encryptedData1.length % 16 !== 0) {
335
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData1.length);
311
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData1.length);
336
312
  reject(new Error("encryptedData length is not a multiple of 16"));
337
313
  return;
338
314
  }
@@ -340,15 +316,15 @@ async function $1c57ad353fa3519e$var$getEncryptedChromeCookie({ name: name , dom
340
316
  try {
341
317
  decipher.final("utf-8");
342
318
  } catch (e) {
343
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing decipher.final()", e);
319
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing decipher.final()", e);
344
320
  reject(e);
345
321
  return;
346
322
  }
347
323
  const padding = decoded[decoded.length - 1];
348
324
  if (padding) decoded = decoded.slice(0, 0 - padding);
349
325
  // noinspection JSCheckFunctionSignatures
350
- decoded = decoded.toString("utf8");
351
- resolve(decoded);
326
+ const decodedString = decoded.toString("utf8");
327
+ resolve(decodedString);
352
328
  } catch (e1) {
353
329
  reject(e1);
354
330
  }
@@ -363,36 +339,36 @@ async function $1c57ad353fa3519e$var$getEncryptedChromeCookie({ name: name , dom
363
339
 
364
340
 
365
341
 
366
- class $d66ab4010a2fe667$export$2e2bcd8739ae039 extends (0, $36bba8acd7b702be$export$2e2bcd8739ae039) {
342
+
343
+ class $7bb7da9a77b2fd99$export$2e2bcd8739ae039 extends (0, $503d2a3d296fcf21$export$2e2bcd8739ae039) {
367
344
  async queryCookies(name, domain) {
368
345
  if (process.platform !== "darwin") throw new Error("This only works on macOS");
369
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).CHROME_ONLY) return [];
346
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).CHROME_ONLY) return [];
370
347
  const cookies = await this.#getFirefoxCookie({
371
348
  name: name,
372
349
  domain: domain
373
350
  });
374
- return Array.isArray(cookies) ? cookies.map((0, $c0cdc003fbf917f0$export$d53bf2de587a369)) : [];
351
+ return Array.isArray(cookies) ? cookies.map((0, $25b78d6746d4ad48$export$d53bf2de587a369)) : [];
375
352
  }
376
353
  /**
377
354
  *
378
355
  * @param name
379
356
  * @param domain
380
357
  * @returns {Promise<Buffer>}
381
- */ async #getFirefoxCookie({ name: name , domain: domain }) {
382
- if (name && typeof name !== "string") throw new Error("name must be a string");
383
- if (domain && typeof domain !== "string") throw new Error("domain must be a string");
384
- const files = await (0, $d6c2e79f3cdd498d$export$2c9faf86071156ae)({
385
- path: $bU6Ve$path.join((0, $fa5ed5287f8fdf72$export$a7c5707626fc90f), "Library", "Application Support", "Firefox", "Profiles"),
358
+ */ async #getFirefoxCookie(//
359
+ { name: name , domain: domain }) {
360
+ const files = await (0, $e62c2c56eb720f29$export$2c9faf86071156ae)({
361
+ path: $bU6Ve$path.join((0, $fac425c10fbbada5$export$a7c5707626fc90f), "Library", "Application Support", "Firefox", "Profiles"),
386
362
  name: "cookies.sqlite"
387
363
  });
388
- const all = Promise.all(files.map((file)=>{
364
+ const all = await Promise.all(files.map((file)=>{
389
365
  return this.#queryCookiesDb(file, name, domain);
390
366
  }));
391
367
  return all.flat();
392
368
  }
393
369
  #queryCookiesDb(file, name1, domain1) {
394
370
  if (file && !(0, $bU6Ve$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
395
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying Firefox cookie ${name1} for domain ${domain1}`);
371
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying Firefox cookie ${name1} for domain ${domain1}`);
396
372
  let sql;
397
373
  //language=SQL
398
374
  sql = "SELECT value FROM moz_cookies";
@@ -404,32 +380,42 @@ class $d66ab4010a2fe667$export$2e2bcd8739ae039 extends (0, $36bba8acd7b702be$exp
404
380
  }
405
381
  if (typeof domain1 === "string") sql += `host LIKE '${domain1}';`;
406
382
  }
407
- return (0, $c0cdc003fbf917f0$export$f19f611d1fa7c6f3)(file, sql).then((rows)=>rows.map((0, $c0cdc003fbf917f0$export$d53bf2de587a369))).catch(()=>[]);
383
+ return (0, $a085b524d8ee9fce$export$f19f611d1fa7c6f3)(file, sql).then((rows)=>{
384
+ return rows.map((row)=>{
385
+ return {
386
+ domain: row.domain,
387
+ name: row.name,
388
+ value: row.value.toString("utf8")
389
+ };
390
+ });
391
+ }).catch(()=>[]);
408
392
  }
409
393
  }
410
394
 
411
395
 
412
396
 
413
- class $ebf338ffba2ec9e7$export$2e2bcd8739ae039 extends (0, $36bba8acd7b702be$export$2e2bcd8739ae039) {
397
+ class $fad6f51bd5c7bae2$export$2e2bcd8739ae039 extends (0, $503d2a3d296fcf21$export$2e2bcd8739ae039) {
414
398
  }
415
399
 
416
400
 
417
401
 
418
- class $b4be7ecb8cbd1374$export$2e2bcd8739ae039 extends (0, $36bba8acd7b702be$export$2e2bcd8739ae039) {
402
+ class $f72befa528c23ca7$export$2e2bcd8739ae039 extends (0, $503d2a3d296fcf21$export$2e2bcd8739ae039) {
419
403
  #strategies;
420
404
  constructor(){
421
405
  super();
422
406
  this.#strategies = [
423
- (0, $1c57ad353fa3519e$export$2e2bcd8739ae039),
424
- (0, $d66ab4010a2fe667$export$2e2bcd8739ae039),
425
- (0, $ebf338ffba2ec9e7$export$2e2bcd8739ae039),
407
+ (0, $269fe42bfd555305$export$2e2bcd8739ae039),
408
+ (0, $7bb7da9a77b2fd99$export$2e2bcd8739ae039),
409
+ (0, $fad6f51bd5c7bae2$export$2e2bcd8739ae039),
426
410
  ].map((strategy)=>{
427
411
  return new strategy();
428
412
  });
429
413
  }
430
414
  async queryCookies(name, domain) {
431
415
  const results = await Promise.all(this.#strategies.map(async (strategy)=>{
432
- return strategy.queryCookies(name, domain).catch(()=>[]);
416
+ // @ts-ignore
417
+ const cookies = strategy.queryCookies(name, domain);
418
+ return cookies.catch(()=>[]);
433
419
  }));
434
420
  return results.flat();
435
421
  }
@@ -440,13 +426,12 @@ class $b4be7ecb8cbd1374$export$2e2bcd8739ae039 extends (0, $36bba8acd7b702be$exp
440
426
 
441
427
 
442
428
 
443
- function $e0bc45c44166a2ff$export$2e2bcd8739ae039(token) {
444
- if (typeof token !== "string") return false;
429
+ function $9a6b2ace073cf1d7$export$2e2bcd8739ae039(token) {
445
430
  try {
446
431
  const result = (0, ($parcel$interopDefault($bU6Ve$jsonwebtoken))).decode(token, {
447
432
  complete: true
448
433
  });
449
- if ((0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).VERBOSE) console.log(result);
434
+ if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(result);
450
435
  return true;
451
436
  } catch (err) {
452
437
  return false;
@@ -454,23 +439,16 @@ function $e0bc45c44166a2ff$export$2e2bcd8739ae039(token) {
454
439
  }
455
440
 
456
441
 
457
- async function $8dc1bcea169affbc$export$e6d428437cf2cacb({ name: name , domain: domain }, strategy = new (0, $b4be7ecb8cbd1374$export$2e2bcd8739ae039)()) {
442
+ async function $7a068a32d4710f0b$export$e6d428437cf2cacb({ name: name , domain: domain }, strategy = new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)()) {
458
443
  const results = await strategy.queryCookies(name, domain);
459
- const results1 = (0, $bU6Ve$lodash.uniq)(results).map((cookie)=>{
460
- return {
461
- name: name,
462
- domain: domain,
463
- value: cookie
464
- };
465
- });
444
+ const results1 = (0, $bU6Ve$lodash.uniqBy)(results, JSON.stringify);
466
445
  const jwtCookies = [];
467
446
  for (const result of results1){
468
447
  const value = result.value;
469
- if ((0, $e0bc45c44166a2ff$export$2e2bcd8739ae039)(value)) jwtCookies.push(result);
448
+ if ((0, $9a6b2ace073cf1d7$export$2e2bcd8739ae039)(value)) jwtCookies.push(result);
470
449
  }
471
- const results2 = (0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).REQUIRE_JWT ? jwtCookies : results1;
472
- const resultsUniq = (0, $bU6Ve$lodash.uniq)(results2).map((cookie)=>cookie.value);
473
- return (0, $fa5ed5287f8fdf72$export$a7b6bc01c63cdfc3).SINGLE ? [
450
+ const resultsUniq = (0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).REQUIRE_JWT ? jwtCookies : results1;
451
+ return (0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).SINGLE ? [
474
452
  resultsUniq[0]
475
453
  ] : resultsUniq;
476
454
  }
@@ -480,17 +458,17 @@ async function $8dc1bcea169affbc$export$e6d428437cf2cacb({ name: name , domain:
480
458
 
481
459
 
482
460
  async function $af7abeb0794bd6fa$export$4be65e66cfa2648a(params) {
483
- const cookies = await (0, $8dc1bcea169affbc$export$e6d428437cf2cacb)(params, new (0, $b4be7ecb8cbd1374$export$2e2bcd8739ae039)());
461
+ const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)());
484
462
  if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
485
463
  else throw new Error("Cookie not found");
486
464
  }
487
465
  async function $af7abeb0794bd6fa$export$c44c5fdef43f0941(params) {
488
- const cookies = await (0, $8dc1bcea169affbc$export$e6d428437cf2cacb)(params, new (0, $d66ab4010a2fe667$export$2e2bcd8739ae039)());
466
+ const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $7bb7da9a77b2fd99$export$2e2bcd8739ae039)());
489
467
  if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
490
468
  else throw new Error("Cookie not found");
491
469
  }
492
470
  async function $af7abeb0794bd6fa$export$e5637297e9eb6f2e(params) {
493
- const cookies = await (0, $8dc1bcea169affbc$export$e6d428437cf2cacb)(params, new (0, $1c57ad353fa3519e$export$2e2bcd8739ae039)());
471
+ const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $269fe42bfd555305$export$2e2bcd8739ae039)());
494
472
  if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
495
473
  else throw new Error("Cookie not found");
496
474
  }