@mherod/get-cookie 2.0.0-rc.2 → 2.0.0-rc.21

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 (50) hide show
  1. package/.idea/runConfigurations/build.xml +12 -0
  2. package/.prettierignore +5 -0
  3. package/README.md +2 -2
  4. package/dist/cli.js +1110 -2
  5. package/dist/index.js +642 -231
  6. package/dist/index.js.map +1 -1
  7. package/dist/module.js +634 -224
  8. package/dist/module.js.map +1 -1
  9. package/dist/types.d.ts +246 -34
  10. package/dist/types.d.ts.map +1 -1
  11. package/package-lock.json +7539 -0
  12. package/package.json +24 -22
  13. package/src/CookieRow.ts +2 -1
  14. package/src/CookieSpec.ts +4 -2
  15. package/src/CookieStore.ts +27 -0
  16. package/src/ExportedCookie.ts +2 -1
  17. package/src/FetchResponse.ts +2 -0
  18. package/src/FileCookieStore.ts +170 -0
  19. package/src/IsCookieRow.ts +1 -1
  20. package/src/IsExportedCookie.ts +1 -1
  21. package/src/SpecialCases.ts +1 -1
  22. package/src/StringToRegex.ts +6 -0
  23. package/src/argv.ts +19 -0
  24. package/src/browsers/ChromeCookieQueryStrategy.ts +106 -24
  25. package/src/browsers/CompositeCookieQueryStrategy.ts +32 -8
  26. package/src/browsers/CookieQueryStrategy.ts +3 -1
  27. package/src/browsers/CookieStoreQueryStrategy.ts +99 -0
  28. package/src/browsers/FirefoxCookieQueryStrategy.ts +57 -9
  29. package/src/browsers/SafariCookieQueryStrategy.ts +4 -1
  30. package/src/cli.ts +101 -93
  31. package/src/comboQueryCookieSpec.ts +24 -0
  32. package/src/cookieSpecsFromUrl.ts +26 -0
  33. package/src/doSqliteQuery1Params.ts +8 -0
  34. package/src/fetchWithCookies.ts +131 -40
  35. package/src/findAllFiles.ts +5 -9
  36. package/src/getChromeCookie.ts +19 -0
  37. package/src/getCookie.ts +19 -0
  38. package/src/getFirefoxCookie.ts +19 -0
  39. package/src/getGroupedRenderedCookies.ts +12 -25
  40. package/src/getMergedRenderedCookies.ts +14 -0
  41. package/src/index.ts +13 -52
  42. package/src/isValidJwt.ts +2 -2
  43. package/src/queryCookies.ts +16 -12
  44. package/src/resultsRendered.ts +7 -4
  45. package/src/unpackHeaders.ts +7 -4
  46. package/src/utils.ts +0 -25
  47. package/tsconfig.json +11 -15
  48. package/.github/dependabot.yml +0 -6
  49. package/dist/cli.js.map +0 -1
  50. package/src/doSqliteQuery1.ts +0 -51
package/dist/index.js CHANGED
@@ -1,14 +1,18 @@
1
1
  #!/usr/bin/env node
2
- var $7oI3p$lodash = require("lodash");
3
- var $7oI3p$lrucache = require("lru-cache");
4
- var $7oI3p$fs = require("fs");
5
- var $7oI3p$crypto = require("crypto");
6
- var $7oI3p$path = require("path");
7
- var $7oI3p$child_process = require("child_process");
8
- var $7oI3p$sqlite3 = require("sqlite3");
9
- var $7oI3p$jsonwebtoken = require("jsonwebtoken");
10
- var $7oI3p$crossfetch = require("cross-fetch");
11
- var $7oI3p$destr = require("destr");
2
+ var $cDXzb$lodash = require("lodash");
3
+ var $cDXzb$minimist = require("minimist");
4
+ var $cDXzb$lrucache = require("lru-cache");
5
+ var $cDXzb$colorette = require("colorette");
6
+ var $cDXzb$fs = require("fs");
7
+ var $cDXzb$crypto = require("crypto");
8
+ var $cDXzb$path = require("path");
9
+ var $cDXzb$sqlite3 = require("sqlite3");
10
+ var $cDXzb$child_process = require("child_process");
11
+ var $cDXzb$toughcookie = require("tough-cookie");
12
+ var $cDXzb$destr = require("destr");
13
+ var $cDXzb$jsonwebtoken = require("jsonwebtoken");
14
+ var $cDXzb$crossfetch = require("cross-fetch");
15
+ var $cDXzb$useragents = require("user-agents");
12
16
 
13
17
  function $parcel$export(e, n, v, s) {
14
18
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
@@ -33,23 +37,27 @@ function $parcel$interopDefault(a) {
33
37
  return a && a.__esModule ? a.default : a;
34
38
  }
35
39
 
36
- $parcel$export(module.exports, "getCookie", () => $cd1ba0160120c006$export$4be65e66cfa2648a);
37
- $parcel$export(module.exports, "getFirefoxCookie", () => $cd1ba0160120c006$export$c44c5fdef43f0941);
38
- $parcel$export(module.exports, "getChromeCookie", () => $cd1ba0160120c006$export$e5637297e9eb6f2e);
39
- $parcel$export(module.exports, "getGroupedRenderedCookies", () => $300d8b33187a203c$export$4d2e9997e2c23417);
40
- $parcel$export(module.exports, "fetchWithCookies", () => $cfc07ae4aa2c7e44$export$b24a545a0b39f491);
40
+ $parcel$export(module.exports, "getCookie", () => $5059c79c511ef67d$export$4be65e66cfa2648a);
41
+ $parcel$export(module.exports, "getChromeCookie", () => $0d142dad92c7a441$export$e5637297e9eb6f2e);
42
+ $parcel$export(module.exports, "getFirefoxCookie", () => $2c9cc1b8a57118d9$export$c44c5fdef43f0941);
43
+ $parcel$export(module.exports, "getMergedRenderedCookies", () => $01a8b57f5e2fbc3a$export$cfc0723de5712e57);
44
+ $parcel$export(module.exports, "getGroupedRenderedCookies", () => $3250e6c7c8746c6f$export$4d2e9997e2c23417);
45
+ $parcel$export(module.exports, "fetchWithCookies", () => $9784c2ab321f9dab$export$b24a545a0b39f491);
41
46
 
42
- const $fac425c10fbbada5$export$a7b6bc01c63cdfc3 = {};
43
- (0, $7oI3p$lodash.merge)($fac425c10fbbada5$export$a7b6bc01c63cdfc3, process.env);
44
- const $fac425c10fbbada5$export$a7c5707626fc90f = $fac425c10fbbada5$export$a7b6bc01c63cdfc3["HOME"];
45
- if (!$fac425c10fbbada5$export$a7c5707626fc90f) throw new Error("HOME environment variable is not set");
46
47
 
47
48
 
49
+ const $7b83c0e89cc28a81$export$6f4ae1207c703045 = process.argv ?? [];
50
+ const $7b83c0e89cc28a81$var$minimistArgs = (0, ($parcel$interopDefault($cDXzb$minimist)))($7b83c0e89cc28a81$export$6f4ae1207c703045.slice(2));
51
+ const $7b83c0e89cc28a81$var$defaultOptions = {
52
+ verbose: false
53
+ };
54
+ const $7b83c0e89cc28a81$export$c348dfaf65040d9b = (0, $cDXzb$lodash.merge)($7b83c0e89cc28a81$var$defaultOptions, $7b83c0e89cc28a81$var$minimistArgs);
48
55
 
49
56
 
50
- async function $25b78d6746d4ad48$export$8d71c74f97c0202e(command) {
57
+
58
+ async function $564742ddd35242d9$export$8d71c74f97c0202e(command) {
51
59
  return new Promise((resolve, reject)=>{
52
- (0, $7oI3p$child_process.exec)(command, {
60
+ (0, $cDXzb$child_process.exec)(command, {
53
61
  encoding: "binary",
54
62
  maxBuffer: 5120
55
63
  }, (error, stdout, stderr)=>{
@@ -65,60 +73,51 @@ async function $25b78d6746d4ad48$export$8d71c74f97c0202e(command) {
65
73
  });
66
74
  });
67
75
  }
68
- function $25b78d6746d4ad48$export$d53bf2de587a369(result) {
69
- if (result == null) return null;
70
- if (process.env.VERBOSE) console.log("result", result);
71
- if (typeof result === "string" && result.length > 0) return result;
72
- if (result.slice && result.toString) // noinspection JSCheckFunctionSignatures
73
- return result.toString("utf8");
74
- return null;
75
- }
76
- function $25b78d6746d4ad48$export$99ce3e33a555daf1(input) {
77
- return typeof input !== "string" || input.length === 0;
78
- }
79
- function $25b78d6746d4ad48$export$5348b46700dd771c(input) {
80
- return typeof input == "string" && input.length > 0;
81
- }
82
76
 
83
77
 
84
78
 
79
+ const $9aaa37efbfec96e1$export$a7b6bc01c63cdfc3 = {};
80
+ (0, $cDXzb$lodash.merge)($9aaa37efbfec96e1$export$a7b6bc01c63cdfc3, process.env);
81
+ const $9aaa37efbfec96e1$export$a7c5707626fc90f = $9aaa37efbfec96e1$export$a7b6bc01c63cdfc3["HOME"];
82
+ if (!$9aaa37efbfec96e1$export$a7c5707626fc90f) throw new Error("HOME environment variable is not set");
83
+
85
84
 
86
85
 
87
86
 
88
- async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: name , maxDepth: maxDepth = 2 }) {
87
+
88
+ async function $80bd1d9d7f29d893$export$2c9faf86071156ae({ path: path , name: name , maxDepth: maxDepth = 2 }) {
89
89
  const rootSegments = path.split("/").length;
90
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Searching for ${name} in ${path}`);
91
90
  const files = [];
92
91
  let readdirSync;
93
92
  try {
94
- readdirSync = $7oI3p$fs.readdirSync(path);
93
+ readdirSync = $cDXzb$fs.readdirSync(path);
95
94
  } catch (e) {
96
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Error reading ${path}`, e);
95
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log(`Error reading ${path}`, e);
97
96
  return [];
98
97
  }
99
98
  for (const file of readdirSync){
100
99
  const filePath = path + "/" + file;
101
100
  let stat;
102
101
  try {
103
- stat = $7oI3p$fs.statSync(filePath);
102
+ stat = $cDXzb$fs.statSync(filePath);
104
103
  } catch (e1) {
105
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.error(`Error getting stat for ${filePath}`, e1);
104
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.error(`Error getting stat for ${filePath}`, e1);
106
105
  continue;
107
106
  }
108
107
  if (stat.isDirectory()) {
109
108
  if (filePath.split("/").length < rootSegments + maxDepth) try {
110
- const subFiles = await $e62c2c56eb720f29$export$2c9faf86071156ae({
109
+ const subFiles = await $80bd1d9d7f29d893$export$2c9faf86071156ae({
111
110
  path: filePath,
112
111
  name: name,
113
112
  maxDepth: 2
114
113
  });
115
114
  files.push(...subFiles);
116
115
  } catch (e2) {
117
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.error(e2);
116
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.error(e2);
118
117
  }
119
118
  } else if (file === name) files.push(filePath);
120
119
  }
121
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) {
120
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) {
122
121
  if (files.length > 0) {
123
122
  console.log(`Found ${files.length} ${name} files`);
124
123
  console.log(files);
@@ -131,158 +130,157 @@ async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: na
131
130
 
132
131
 
133
132
 
134
-
135
-
136
- async function $a085b524d8ee9fce$export$f19f611d1fa7c6f3({ file: file , sql: sql , rowTransform: rowTransform }) {
137
- if (!file || file && !$7oI3p$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
138
- const db = new $7oI3p$sqlite3.Database(file);
139
- return new Promise((resolve, reject)=>{
140
- db.all(sql, (err, rows)=>{
141
- if (err) {
142
- reject(err);
143
- return;
144
- }
145
- const rows1 = rows;
146
- if (rows1 == null || rows1.length === 0) {
147
- resolve([]);
148
- return;
149
- }
150
- if (Array.isArray(rows1)) {
151
- const cookieRows = rows1.map((row)=>{
152
- const newVar = {
153
- meta: {
154
- file: file
155
- }
156
- };
157
- const cookieRow = rowTransform(row);
158
- return (0, $7oI3p$lodash.merge)(newVar, cookieRow);
159
- });
160
- resolve(cookieRows);
161
- return;
162
- }
163
- if (process.env.VERBOSE) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
164
- resolve([
165
- rows1
166
- ]);
167
- });
168
- });
133
+ function $f490d8883fd09138$export$bc926c43858bd3cb(obj) {
134
+ return obj.domain !== undefined && obj.name !== undefined && obj.value !== undefined;
169
135
  }
170
136
 
171
137
 
172
-
173
- function $af69dfb8766652d8$export$bc926c43858bd3cb(obj) {
138
+ function $5ab7b2322194eec8$export$963c8d651337e4a4(obj) {
174
139
  return obj.domain !== undefined && obj.name !== undefined && obj.value !== undefined;
175
140
  }
176
141
 
177
142
 
178
- function $d66f40b581ba8bfa$export$963c8d651337e4a4(obj) {
179
- return obj.domain !== undefined && obj.name !== undefined && obj.value !== undefined;
143
+ function $0dadf812b76e7b53$export$4eadcf0bf35a2ddb(s) {
144
+ const s1 = s.replaceAll(/\./gi, ".");
145
+ const s2 = s1.replace(/%/g, ".*");
146
+ const s3 = s2.replace(/\*/g, ".*");
147
+ return new RegExp(s3);
180
148
  }
181
149
 
182
150
 
183
- class $269fe42bfd555305$export$2e2bcd8739ae039 {
151
+
152
+
153
+ class $2863e754fd8bb18c$export$2e2bcd8739ae039 {
154
+ browserName = "Chrome";
184
155
  async queryCookies(name, domain) {
185
156
  if (process.platform !== "darwin") throw new Error("This only works on macOS");
186
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).FIREFOX_ONLY) return [];
187
- return $269fe42bfd555305$var$getChromeCookies({
157
+ if ((0, $9aaa37efbfec96e1$export$a7b6bc01c63cdfc3).FIREFOX_ONLY) return [];
158
+ return $2863e754fd8bb18c$var$getChromeCookies({
188
159
  requireJwt: false,
189
160
  name: name,
190
161
  domain: domain
191
162
  });
192
163
  }
193
164
  }
194
- async function $269fe42bfd555305$var$getPromise1(name, domain, file) {
165
+ async function $2863e754fd8bb18c$var$getPromise1(name, domain, file) {
195
166
  try {
196
- return await $269fe42bfd555305$var$getEncryptedChromeCookie({
167
+ return await $2863e754fd8bb18c$var$getEncryptedChromeCookie({
197
168
  name: name,
198
169
  domain: domain,
199
170
  file: file
200
171
  });
201
172
  } catch (e) {
202
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error getting encrypted cookie", e);
173
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log("Error getting encrypted cookie", e);
203
174
  return [];
204
175
  }
205
176
  }
206
- async function $269fe42bfd555305$var$getPromise(name, domain) {
177
+ async function $2863e754fd8bb18c$var$getPromise(name, domain) {
207
178
  try {
208
- const files = await (0, $e62c2c56eb720f29$export$2c9faf86071156ae)({
209
- path: $269fe42bfd555305$var$chromeLocal,
179
+ const files = await (0, $80bd1d9d7f29d893$export$2c9faf86071156ae)({
180
+ path: $2863e754fd8bb18c$var$chromeLocal,
210
181
  name: "Cookies"
211
182
  });
212
- const promises = files.map((file)=>$269fe42bfd555305$var$getPromise1(name, domain, file));
183
+ const promises = files.map((file)=>$2863e754fd8bb18c$var$getPromise1(name, domain, file));
213
184
  const results1 = await Promise.all(promises);
214
- return results1.flat().filter((0, $af69dfb8766652d8$export$bc926c43858bd3cb));
185
+ return results1.flat().filter((0, $f490d8883fd09138$export$bc926c43858bd3cb));
215
186
  } catch (error) {
216
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("error", error);
187
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log("error", error);
217
188
  return [];
218
189
  }
219
190
  }
220
- async function $269fe42bfd555305$var$decryptValue(password, encryptedValue) {
191
+ async function $2863e754fd8bb18c$var$decryptValue(password, encryptedValue) {
221
192
  let d;
222
193
  try {
223
- d = await $269fe42bfd555305$var$decrypt(password, encryptedValue);
194
+ d = await $2863e754fd8bb18c$var$decrypt(password, encryptedValue);
224
195
  } catch (e) {
225
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error decrypting cookie", e);
196
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log("Error decrypting cookie", e);
226
197
  d = null;
227
198
  }
228
199
  return d ?? encryptedValue.toString("utf-8");
229
200
  }
230
- async function $269fe42bfd555305$var$getChromeCookies({ name: name , domain: domain = "%" , requireJwt: requireJwt = false }) {
231
- const encryptedDataItems = await $269fe42bfd555305$var$getPromise(name, domain);
232
- const password = await $269fe42bfd555305$var$getChromePassword();
201
+ async function $2863e754fd8bb18c$var$getChromeCookies({ name: name , domain: domain = "%" , requireJwt: requireJwt = false }) {
202
+ const encryptedDataItems = await $2863e754fd8bb18c$var$getPromise(name, domain);
203
+ const password = await $2863e754fd8bb18c$var$getChromePassword();
233
204
  const decrypted = encryptedDataItems.filter(({ value: value })=>value != null && value.length > 0).map(async (cookieRow)=>{
234
205
  const encryptedValue = cookieRow.value;
235
- const decryptedValue = await $269fe42bfd555305$var$decryptValue(password, encryptedValue);
206
+ const decryptedValue = await $2863e754fd8bb18c$var$decryptValue(password, encryptedValue);
236
207
  const meta = {};
237
- (0, $7oI3p$lodash.merge)(meta, cookieRow.meta ?? {});
238
- return {
208
+ (0, $cDXzb$lodash.merge)(meta, cookieRow.meta ?? {});
209
+ const exportedCookie = {
239
210
  domain: cookieRow.domain,
240
211
  name: cookieRow.name,
241
212
  value: decryptedValue,
242
213
  meta: meta
243
214
  };
215
+ const expiry = cookieRow.expiry;
216
+ const mergeExpiry = expiry != null && expiry > 0 ? {
217
+ expiry: new Date(expiry)
218
+ } : {
219
+ expiry: "Infinity"
220
+ };
221
+ (0, $cDXzb$lodash.merge)(exportedCookie, mergeExpiry);
222
+ return exportedCookie;
244
223
  });
245
- const results = (await Promise.all(decrypted)).filter((0, $d66f40b581ba8bfa$export$963c8d651337e4a4));
246
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("results", results);
224
+ const results = (await Promise.all(decrypted)).filter((0, $5ab7b2322194eec8$export$963c8d651337e4a4));
225
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log("results", results);
247
226
  return results;
248
227
  }
249
- const $269fe42bfd555305$var$chromeLocal = $7oI3p$path.join((0, $fac425c10fbbada5$export$a7c5707626fc90f), "Library", "Application Support", "Google", "Chrome");
250
- async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , domain: domain , file: file = $7oI3p$path.join($269fe42bfd555305$var$chromeLocal, "Default", "Cookies") }) {
251
- if (!(0, $7oI3p$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
252
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) {
228
+ const $2863e754fd8bb18c$var$chromeLocal = $cDXzb$path.join((0, $9aaa37efbfec96e1$export$a7c5707626fc90f), "Library", "Application Support", "Google", "Chrome");
229
+ async function $2863e754fd8bb18c$var$getEncryptedChromeCookie({ name: name , domain: domain , file: file = $cDXzb$path.join($2863e754fd8bb18c$var$chromeLocal, "Default", "Cookies") }) {
230
+ if (!(0, $cDXzb$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
231
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) {
253
232
  const s = file.split("/").slice(-3).join("/");
254
233
  console.log(`Trying Chrome (at ${s}) cookie ${name} for domain ${domain}`);
255
234
  }
256
235
  let sql;
257
236
  //language=SQL
258
- sql = "SELECT encrypted_value, name, host_key FROM cookies";
237
+ sql = "SELECT * FROM cookies";
238
+ // sql = "SELECT encrypted_value, name, host_key FROM cookies";
259
239
  const wildcardRegexp = /^([*%])$/i;
260
240
  const specifiedName = name.match(wildcardRegexp) == null;
261
241
  const specifiedDomain = domain.match(wildcardRegexp) == null;
262
- if (specifiedName || specifiedDomain) {
242
+ const wildcardDomain = domain.match(/[%*]/) != null;
243
+ const queryDomain = specifiedDomain && !wildcardDomain;
244
+ // if we have a wildcard domain, we need to use a regexp
245
+ if (specifiedName || queryDomain) {
263
246
  sql += ` WHERE `;
264
247
  if (specifiedName) {
265
248
  sql += `name = '${name}'`;
266
- if (specifiedDomain) sql += ` AND `;
249
+ if (queryDomain) sql += ` AND `;
250
+ }
251
+ if (queryDomain) {
252
+ // leading dot replaced with % to match subdomains
253
+ const sqlEmbedDomain = domain.replace(/^[.%]?/, "%");
254
+ sql += `host_key LIKE '${sqlEmbedDomain}';`;
267
255
  }
268
- if (specifiedDomain) sql += `host_key LIKE '${domain}';`;
269
256
  }
270
- return (0, $a085b524d8ee9fce$export$f19f611d1fa7c6f3)({
257
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log("sql", sql);
258
+ const domainRegexp = (0, $0dadf812b76e7b53$export$4eadcf0bf35a2ddb)(domain);
259
+ const sqliteQuery1 = await $2863e754fd8bb18c$export$bd52b72df8d0d261({
271
260
  file: file,
272
261
  sql: sql,
262
+ rowFilter: (row)=>{
263
+ return row["host_key"].match(domainRegexp) != null;
264
+ },
273
265
  rowTransform: (row)=>{
274
- return {
266
+ const cookieRow = {
267
+ expiry: (row["expires_utc"] / 1000000 - 11644473600) * 1000,
275
268
  domain: row["host_key"],
276
269
  name: row["name"],
277
270
  value: row["encrypted_value"]
278
271
  };
272
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log("CookieRow", cookieRow);
273
+ return cookieRow;
279
274
  }
280
275
  });
276
+ return sqliteQuery1.filter((row)=>{
277
+ return row.domain.match(domainRegexp) != null;
278
+ });
281
279
  }
282
- async function $269fe42bfd555305$var$getChromePassword() {
283
- return (0, $25b78d6746d4ad48$export$8d71c74f97c0202e)('security find-generic-password -w -s "Chrome Safe Storage"');
280
+ async function $2863e754fd8bb18c$var$getChromePassword() {
281
+ return (0, $564742ddd35242d9$export$8d71c74f97c0202e)('security find-generic-password -w -s "Chrome Safe Storage"');
284
282
  }
285
- async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
283
+ async function $2863e754fd8bb18c$var$decrypt(password, encryptedData) {
286
284
  if (typeof password !== "string") throw new Error("password must be a string: " + password);
287
285
  let encryptedData1;
288
286
  encryptedData1 = encryptedData;
@@ -290,31 +288,31 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
290
288
  if (!(encryptedData1 instanceof Buffer)) {
291
289
  if (Array.isArray(encryptedData1) && encryptedData1[0] instanceof Buffer) {
292
290
  [encryptedData1] = encryptedData1;
293
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`encryptedData is an array of buffers, selected first: ${encryptedData1}`);
291
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log(`encryptedData is an array of buffers, selected first: ${encryptedData1}`);
294
292
  } else throw new Error("encryptedData must be a Buffer: " + encryptedData1);
295
293
  encryptedData1 = Buffer.from(encryptedData1);
296
294
  }
297
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(`Trying to decrypt with password ${password}`);
295
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log(`Trying to decrypt with password ${password}`);
298
296
  return new Promise((resolve, reject)=>{
299
- $7oI3p$crypto.pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer)=>{
297
+ $cDXzb$crypto.pbkdf2(password, "saltysalt", 1003, 16, "sha1", (error, buffer)=>{
300
298
  try {
301
299
  if (error) {
302
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2", error);
300
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log("Error doing pbkdf2", error);
303
301
  reject(error);
304
302
  return;
305
303
  }
306
304
  if (buffer.length !== 16) {
307
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, buffer length is not 16", buffer.length);
305
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log("Error doing pbkdf2, buffer length is not 16", buffer.length);
308
306
  reject(new Error("Buffer length is not 16"));
309
307
  return;
310
308
  }
311
309
  const str = new Array(17).join(" ");
312
310
  const iv = Buffer.from(str, "binary");
313
- const decipher = $7oI3p$crypto.createDecipheriv("aes-128-cbc", buffer, iv);
311
+ const decipher = $cDXzb$crypto.createDecipheriv("aes-128-cbc", buffer, iv);
314
312
  decipher.setAutoPadding(false);
315
313
  if (encryptedData1 && encryptedData1.slice) encryptedData1 = encryptedData1.slice(3);
316
314
  if (encryptedData1.length % 16 !== 0) {
317
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData1.length);
315
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log("Error doing pbkdf2, encryptedData length is not a multiple of 16", encryptedData1.length);
318
316
  reject(new Error("encryptedData length is not a multiple of 16"));
319
317
  return;
320
318
  }
@@ -322,7 +320,7 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
322
320
  try {
323
321
  decipher.final("utf-8");
324
322
  } catch (e) {
325
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log("Error doing decipher.final()", e);
323
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log("Error doing decipher.final()", e);
326
324
  reject(e);
327
325
  return;
328
326
  }
@@ -337,14 +335,47 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
337
335
  });
338
336
  });
339
337
  }
338
+ async function $2863e754fd8bb18c$export$bd52b72df8d0d261({ file: file , sql: sql , rowFilter: rowFilter = ()=>true , rowTransform: rowTransform }) {
339
+ if (!file || file && !(0, ($parcel$interopDefault($cDXzb$fs))).existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
340
+ const db = new $cDXzb$sqlite3.Database(file);
341
+ return new Promise((resolve, reject)=>{
342
+ db.all(sql, (err, rows)=>{
343
+ if (err) {
344
+ reject(err);
345
+ return;
346
+ }
347
+ const rows1 = rows;
348
+ if (rows1 == null || rows1.length === 0) {
349
+ resolve([]);
350
+ return;
351
+ }
352
+ if (Array.isArray(rows1)) {
353
+ const cookieRows = rows1.filter(rowFilter).map((row)=>{
354
+ const newVar = {
355
+ meta: {
356
+ file: file
357
+ }
358
+ };
359
+ const cookieRow = rowTransform(row);
360
+ return (0, $cDXzb$lodash.merge)(newVar, cookieRow);
361
+ });
362
+ resolve(cookieRows);
363
+ return;
364
+ }
365
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
366
+ resolve([
367
+ rows1
368
+ ]);
369
+ });
370
+ });
371
+ }
340
372
 
341
373
 
342
374
 
343
375
 
344
376
 
345
377
 
346
-
347
- function $b744d19cc39f964e$export$da22813e5a2ec500({ name: name , domain: domain }) {
378
+ function $4cf67f382f391bdd$export$da22813e5a2ec500({ name: name , domain: domain }) {
348
379
  const wildcardRegexp = /^([*%])$/i;
349
380
  return {
350
381
  specifiedName: name.match(wildcardRegexp) == null,
@@ -353,10 +384,49 @@ function $b744d19cc39f964e$export$da22813e5a2ec500({ name: name , domain: domain
353
384
  }
354
385
 
355
386
 
356
- class $7bb7da9a77b2fd99$export$2e2bcd8739ae039 {
387
+
388
+
389
+
390
+ async function $5df4e8bfccec8ffc$export$f19f611d1fa7c6f3({ file: file , sql: sql , rowTransform: rowTransform }) {
391
+ if (!file || file && !(0, ($parcel$interopDefault($cDXzb$fs))).existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
392
+ const db = new $cDXzb$sqlite3.Database(file);
393
+ return new Promise((resolve, reject)=>{
394
+ db.all(sql, (err, rows)=>{
395
+ if (err) {
396
+ reject(err);
397
+ return;
398
+ }
399
+ const rows1 = rows;
400
+ if (rows1 == null || rows1.length === 0) {
401
+ resolve([]);
402
+ return;
403
+ }
404
+ if (Array.isArray(rows1)) {
405
+ const cookieRows = rows1.map((row)=>{
406
+ const newVar = {
407
+ meta: {
408
+ file: file
409
+ }
410
+ };
411
+ const cookieRow = rowTransform(row);
412
+ return (0, $cDXzb$lodash.merge)(newVar, cookieRow);
413
+ });
414
+ resolve(cookieRows);
415
+ return;
416
+ }
417
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
418
+ resolve([
419
+ rows1
420
+ ]);
421
+ });
422
+ });
423
+ }
424
+ class $5df4e8bfccec8ffc$export$2e2bcd8739ae039 {
425
+ browserName = "Firefox";
357
426
  async queryCookies(name, domain) {
358
- if (process.platform !== "darwin") throw new Error("This only works on macOS");
359
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).CHROME_ONLY) return [];
427
+ if (process.platform !== "darwin") // TODO: implement
428
+ return [];
429
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).browser !== "firefox") return [];
360
430
  const cookies = await this.#getFirefoxCookie({
361
431
  name: name,
362
432
  domain: domain
@@ -372,22 +442,23 @@ class $7bb7da9a77b2fd99$export$2e2bcd8739ae039 {
372
442
  }
373
443
  async #getFirefoxCookie({ name: name , domain: domain } //
374
444
  ) {
375
- const files = await (0, $e62c2c56eb720f29$export$2c9faf86071156ae)({
376
- path: $7oI3p$path.join((0, $fac425c10fbbada5$export$a7c5707626fc90f), "Library", "Application Support", "Firefox", "Profiles"),
445
+ const files = await (0, $80bd1d9d7f29d893$export$2c9faf86071156ae)({
446
+ path: $cDXzb$path.join((0, $9aaa37efbfec96e1$export$a7c5707626fc90f), "Library", "Application Support", "Firefox", "Profiles"),
377
447
  name: "cookies.sqlite"
378
448
  });
379
449
  const fn = async (file)=>{
380
450
  return await this.#queryCookiesDb(file, name, domain);
381
451
  };
382
452
  const all = await Promise.all(files.map(fn));
453
+ // flatten
383
454
  return all.flat();
384
455
  }
385
456
  async #queryCookiesDb(file, name1, domain1) {
386
- if (file && !(0, $7oI3p$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
457
+ if (file && !(0, $cDXzb$fs.existsSync)(file)) throw new Error(`File ${file} does not exist`);
387
458
  let sql;
388
459
  //language=SQL
389
460
  sql = "SELECT value, name, host FROM moz_cookies";
390
- const { specifiedName: specifiedName , specifiedDomain: specifiedDomain } = (0, $b744d19cc39f964e$export$da22813e5a2ec500)({
461
+ const { specifiedName: specifiedName , specifiedDomain: specifiedDomain } = (0, $4cf67f382f391bdd$export$da22813e5a2ec500)({
391
462
  name: name1,
392
463
  domain: domain1
393
464
  });
@@ -409,7 +480,7 @@ class $7bb7da9a77b2fd99$export$2e2bcd8739ae039 {
409
480
  };
410
481
  };
411
482
  try {
412
- return await (0, $a085b524d8ee9fce$export$f19f611d1fa7c6f3)({
483
+ return await $5df4e8bfccec8ffc$export$f19f611d1fa7c6f3({
413
484
  file: file,
414
485
  sql: sql,
415
486
  rowTransform: rowTransform
@@ -422,40 +493,256 @@ class $7bb7da9a77b2fd99$export$2e2bcd8739ae039 {
422
493
  }
423
494
 
424
495
 
425
- class $fad6f51bd5c7bae2$export$2e2bcd8739ae039 {
496
+ class $0ca9bb20e90816f9$export$2e2bcd8739ae039 {
497
+ browserName = "Safari";
426
498
  async queryCookies(name, domain) {
499
+ // TODO: implement
427
500
  return [];
428
501
  }
429
502
  }
430
503
 
431
504
 
432
505
 
433
- const $f72befa528c23ca7$var$cache = new (0, ($parcel$interopDefault($7oI3p$lrucache)))({
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+ class $30e4b5d3291f1a19$export$55374e421ca433de extends (0, $cDXzb$toughcookie.Store) {
514
+ synchronous = false;
515
+ tasks = [];
516
+ constructor(filePath, internalStore = new (0, $cDXzb$toughcookie.MemoryCookieStore)()){
517
+ super();
518
+ this.filePath = filePath;
519
+ this.internalStore = internalStore ?? new (0, $cDXzb$toughcookie.MemoryCookieStore)();
520
+ console.log("Importing cookies from", filePath, internalStore);
521
+ this.tasks.push(this.importSaved(filePath, internalStore).then(console.log, console.error));
522
+ }
523
+ async importSaved(filePath, store) {
524
+ const cookies = [];
525
+ if ((0, $cDXzb$fs.existsSync)(filePath)) {
526
+ const data = (0, $cDXzb$fs.readFileSync)(filePath, "utf8");
527
+ const cookies1 = Object.values((0, ($parcel$interopDefault($cDXzb$destr)))(data)).flatMap((domainCookies)=>Object.values(domainCookies)).flatMap((domainCookies)=>Object.values(domainCookies));
528
+ console.log("Importing", cookies1.length, "cookies");
529
+ const array = Array.isArray(cookies1) ? cookies1 : Object.values(cookies1);
530
+ const put = await Promise.all(array.map((cookie)=>{
531
+ const fromJSON = (0, $cDXzb$toughcookie.Cookie).fromJSON(cookie);
532
+ if (fromJSON) return this.putCookieInternal(fromJSON, store);
533
+ }));
534
+ cookies1.push(...put);
535
+ }
536
+ return cookies;
537
+ }
538
+ findCookie(domain, path, key, cb) {
539
+ this.waitUntilIdle().finally(()=>{
540
+ this.internalStore.findCookie(domain, path, key, cb);
541
+ });
542
+ }
543
+ findCookies(domain, path, allowSpecialUseDomain, cb) {
544
+ this.waitUntilIdle().finally(()=>{
545
+ this.internalStore.findCookies(domain, path, allowSpecialUseDomain, cb);
546
+ });
547
+ }
548
+ putCookie(cookie, cb) {
549
+ this.internalStore.putCookie(cookie, cb);
550
+ this.internalStore.getAllCookies((err, cookies)=>{
551
+ this.serializeCallback(err, cookies);
552
+ });
553
+ }
554
+ updateCookie(oldCookie, newCookie, cb) {
555
+ this.internalStore.updateCookie(oldCookie, newCookie, cb);
556
+ this.internalStore.getAllCookies((err, cookies)=>{
557
+ this.serializeCallback(err, cookies);
558
+ });
559
+ }
560
+ removeCookie(domain, path, key, cb) {
561
+ this.internalStore.removeCookie(domain, path, key, cb);
562
+ this.internalStore.getAllCookies((err, cookies)=>{
563
+ this.serializeCallback(err, cookies);
564
+ });
565
+ }
566
+ removeCookies(domain, path, cb) {
567
+ this.internalStore.removeCookies(domain, path, cb);
568
+ this.internalStore.getAllCookies((err, cookies)=>{
569
+ this.serializeCallback(err, cookies);
570
+ });
571
+ }
572
+ getAllCookies(cb) {
573
+ this.waitUntilIdle().finally(()=>{
574
+ this.internalStore.getAllCookies(cb);
575
+ });
576
+ }
577
+ waitUntilIdle() {
578
+ return Promise.allSettled(this.tasks).catch(console.error);
579
+ }
580
+ async putCookieInternal(cookie, store) {
581
+ await this.waitUntilIdle();
582
+ return await new Promise((resolve, reject)=>{
583
+ store.putCookie(cookie, (err)=>{
584
+ if (err) reject(err);
585
+ else resolve(cookie);
586
+ });
587
+ });
588
+ }
589
+ serializeCallback(err, cookies) {
590
+ if (err) {
591
+ console.error(err);
592
+ return;
593
+ }
594
+ const cookieObjs = cookies.map((cookie)=>cookie);
595
+ const idx = {};
596
+ for (const cookie of cookieObjs){
597
+ const domain = cookie.domain;
598
+ if (typeof domain === "string") {
599
+ const path = cookie.path ?? "/";
600
+ const key = cookie.key;
601
+ (0, $cDXzb$lodash.merge)(idx, {
602
+ [domain]: {
603
+ [path]: {
604
+ [key]: cookie.toJSON()
605
+ }
606
+ }
607
+ });
608
+ }
609
+ }
610
+ const stringify = JSON.stringify(idx, null, 2);
611
+ (0, $cDXzb$fs.writeFile)(this.filePath, stringify, (err)=>{
612
+ if (err) console.error(err);
613
+ });
614
+ }
615
+ }
616
+
617
+
618
+ const $14bfa2612c55b48d$var$memoryCookieStore = new (0, $cDXzb$toughcookie.MemoryCookieStore)();
619
+ async function $14bfa2612c55b48d$var$getCookieStore() {
620
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b)["cs"] == "memory") return $14bfa2612c55b48d$var$memoryCookieStore;
621
+ const fileCookieStore = new (0, $30e4b5d3291f1a19$export$55374e421ca433de)(`${(0, $9aaa37efbfec96e1$export$a7b6bc01c63cdfc3)["HOME"]}/cookie-star.json`, $14bfa2612c55b48d$var$memoryCookieStore);
622
+ await fileCookieStore.waitUntilIdle();
623
+ return fileCookieStore;
624
+ }
625
+ const $14bfa2612c55b48d$export$2c043f03eceff4e8 = new Promise((resolve)=>{
626
+ $14bfa2612c55b48d$var$getCookieStore().then(resolve);
627
+ });
628
+ const $14bfa2612c55b48d$export$eced8873dedbb4c0 = new Promise((resolve)=>{
629
+ $14bfa2612c55b48d$export$2c043f03eceff4e8.then((store)=>new (0, $cDXzb$toughcookie.CookieJar)(store)).then(resolve);
630
+ });
631
+
632
+
633
+
634
+ class $7fc5b30fe5c37771$export$2e2bcd8739ae039 {
635
+ browserName = "internal";
636
+ async queryCookies(name, domain) {
637
+ const exportedCookies = [];
638
+ // if (name.match(/[%*]/) || domain.match(/[%*]/)) {
639
+ const cookies = await this.#getAllCookies();
640
+ const allExportedCookies = cookies.map((cookie)=>{
641
+ return this.#extracted(cookie, {
642
+ name: name,
643
+ domain: domain
644
+ });
645
+ });
646
+ exportedCookies.push(...allExportedCookies);
647
+ // }
648
+ const wildcardRegexp = /^([*%])$/i;
649
+ if (name.match(wildcardRegexp) && domain.match(wildcardRegexp)) return exportedCookies;
650
+ const path = "/";
651
+ if (domain != "%") {
652
+ const domain1 = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
653
+ const url = new URL("https://" + domain1);
654
+ url.pathname = path;
655
+ const cookies1 = await this.#getCookies(url.href);
656
+ const domainCookies = cookies1.map((cookie)=>{
657
+ return this.#extracted(cookie, {
658
+ domain: domain,
659
+ name: name
660
+ });
661
+ });
662
+ exportedCookies.push(...domainCookies);
663
+ }
664
+ if (name == "%") return exportedCookies.filter((cookie)=>{
665
+ return cookie.domain.match((0, $0dadf812b76e7b53$export$4eadcf0bf35a2ddb)(domain));
666
+ });
667
+ return exportedCookies.filter((cookie)=>{
668
+ return cookie.name.match((0, $0dadf812b76e7b53$export$4eadcf0bf35a2ddb)(name)) && cookie.domain.match((0, $0dadf812b76e7b53$export$4eadcf0bf35a2ddb)(domain));
669
+ });
670
+ }
671
+ #extracted(cookie, cookieSpec) {
672
+ return {
673
+ domain: cookie.domain ?? cookieSpec.domain,
674
+ name: cookie.key ?? cookieSpec.name,
675
+ value: cookie.value,
676
+ expiry: cookie.expires ?? "Infinity",
677
+ meta: {
678
+ file: "tough-cookie"
679
+ }
680
+ };
681
+ }
682
+ async #getCookies(url) {
683
+ const cookieJar = await (0, $14bfa2612c55b48d$export$eced8873dedbb4c0);
684
+ return new Promise((resolve, reject)=>{
685
+ return cookieJar.getCookies(url, (err, cookies)=>{
686
+ if (err) reject(err);
687
+ else resolve(cookies ?? []);
688
+ });
689
+ });
690
+ }
691
+ async #getAllCookies() {
692
+ const cookieStore = await (0, $14bfa2612c55b48d$export$2c043f03eceff4e8);
693
+ return new Promise((resolve, reject)=>{
694
+ return cookieStore.getAllCookies((err, cookies)=>{
695
+ if (err) reject(err);
696
+ else resolve(cookies ?? []);
697
+ });
698
+ });
699
+ }
700
+ }
701
+
702
+
703
+
704
+
705
+
706
+ const $9b213ca499318f10$var$cache = new (0, ($parcel$interopDefault($cDXzb$lrucache)))({
434
707
  ttl: 2000,
435
708
  max: 10
436
709
  });
437
- class $f72befa528c23ca7$export$2e2bcd8739ae039 {
710
+ class $9b213ca499318f10$export$2e2bcd8739ae039 {
711
+ browserName = "all";
438
712
  #strategies;
439
713
  constructor(){
440
714
  this.#strategies = [
441
- (0, $269fe42bfd555305$export$2e2bcd8739ae039),
442
- (0, $7bb7da9a77b2fd99$export$2e2bcd8739ae039),
443
- (0, $fad6f51bd5c7bae2$export$2e2bcd8739ae039),
715
+ (0, $7fc5b30fe5c37771$export$2e2bcd8739ae039),
716
+ (0, $2863e754fd8bb18c$export$2e2bcd8739ae039),
717
+ (0, $5df4e8bfccec8ffc$export$2e2bcd8739ae039),
718
+ (0, $0ca9bb20e90816f9$export$2e2bcd8739ae039),
444
719
  ].map((strategy)=>{
445
720
  return new strategy();
446
721
  });
447
722
  }
448
723
  async queryCookies(name, domain) {
724
+ // domain = domain.match(/(\w+.+\w+)/gi)?.pop() ?? domain;
449
725
  const key = `${name}:${domain}`;
450
- const cached = $f72befa528c23ca7$var$cache.get(key);
726
+ const cached = $9b213ca499318f10$var$cache.get(key);
451
727
  if (cached) return cached;
728
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log("Querying cookies:", name, domain);
452
729
  const results = await Promise.all(this.#strategies.map(async (strategy)=>{
453
730
  // @ts-ignore
454
- const cookies = strategy.queryCookies(name, domain);
455
- return cookies.catch(()=>[]);
731
+ return strategy.queryCookies(name, domain).then((cookies)=>{
732
+ return cookies.map((cookie)=>{
733
+ return (0, $cDXzb$lodash.merge)(cookie, {
734
+ meta: {
735
+ browser: strategy.browserName
736
+ }
737
+ });
738
+ });
739
+ }).catch((e)=>{
740
+ console.log((0, $cDXzb$colorette.red)(`Error querying ${strategy.browserName} cookies`), e);
741
+ return [];
742
+ });
456
743
  }));
457
744
  const flat = results.flat();
458
- $f72befa528c23ca7$var$cache.set(`${name}:${domain}`, flat);
745
+ $9b213ca499318f10$var$cache.set(`${name}:${domain}`, flat);
459
746
  return flat;
460
747
  }
461
748
  }
@@ -463,12 +750,12 @@ class $f72befa528c23ca7$export$2e2bcd8739ae039 {
463
750
 
464
751
 
465
752
 
466
- function $9a6b2ace073cf1d7$export$2e2bcd8739ae039(token) {
753
+ function $02c6d50814f70012$export$2e2bcd8739ae039(token) {
467
754
  try {
468
- const result = (0, ($parcel$interopDefault($7oI3p$jsonwebtoken))).decode(token, {
755
+ const result = (0, ($parcel$interopDefault($cDXzb$jsonwebtoken))).decode(token, {
469
756
  complete: true
470
757
  });
471
- if ((0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).VERBOSE) console.log(result);
758
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose && result) console.log(result);
472
759
  const payload = result?.payload;
473
760
  if (payload) {
474
761
  const exp = payload.exp;
@@ -484,133 +771,257 @@ function $9a6b2ace073cf1d7$export$2e2bcd8739ae039(token) {
484
771
  }
485
772
 
486
773
 
487
- async function $7a068a32d4710f0b$export$e6d428437cf2cacb({ name: name , domain: domain }, strategy = new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)()) {
774
+ async function $adc20573c5fde3a5$export$e6d428437cf2cacb({ name: name , domain: domain }, strategy = new (0, $9b213ca499318f10$export$2e2bcd8739ae039)()) {
488
775
  const results = await strategy.queryCookies(name, domain);
489
- const results1 = (0, $7oI3p$lodash.uniqBy)(results, JSON.stringify);
490
- const jwtCookies = [];
491
- for (const result of results1){
492
- const value = result.value;
493
- if ((0, $9a6b2ace073cf1d7$export$2e2bcd8739ae039)(value)) jwtCookies.push(result);
494
- }
495
- const resultsUniq = (0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).REQUIRE_JWT ? jwtCookies : results1;
496
- return (0, $fac425c10fbbada5$export$a7b6bc01c63cdfc3).SINGLE ? [
497
- resultsUniq[0]
498
- ] : resultsUniq;
776
+ const allCookies = (0, $cDXzb$lodash.uniqBy)(results, JSON.stringify);
777
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b)["require-jwt"]) {
778
+ const jwtCookies = [];
779
+ for (const result of allCookies){
780
+ const value = result.value;
781
+ if ((0, $02c6d50814f70012$export$2e2bcd8739ae039)(value)) jwtCookies.push(result);
782
+ }
783
+ return (0, $7b83c0e89cc28a81$export$c348dfaf65040d9b)["single"] ? [
784
+ jwtCookies[0]
785
+ ] : jwtCookies;
786
+ } else return (0, $7b83c0e89cc28a81$export$c348dfaf65040d9b)["single"] ? [
787
+ allCookies[0]
788
+ ] : allCookies;
789
+ }
790
+
791
+
792
+
793
+ async function $5059c79c511ef67d$export$4be65e66cfa2648a(params) {
794
+ const cookies = await (0, $adc20573c5fde3a5$export$e6d428437cf2cacb)(params, new (0, $9b213ca499318f10$export$2e2bcd8739ae039)());
795
+ if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
796
+ else throw new Error("Cookie not found");
499
797
  }
500
798
 
501
799
 
502
800
 
503
801
 
504
802
 
803
+ async function $0d142dad92c7a441$export$e5637297e9eb6f2e(params) {
804
+ const cookies = await (0, $adc20573c5fde3a5$export$e6d428437cf2cacb)(params, new (0, $2863e754fd8bb18c$export$2e2bcd8739ae039)());
805
+ if (cookies.length == 0) throw new Error("Cookie not found");
806
+ return cookies.find((0, $5ab7b2322194eec8$export$963c8d651337e4a4));
807
+ }
505
808
 
506
809
 
507
810
 
508
811
 
509
- function $9c43c2ed82e63570$export$9abc0a414b0d8b8f(results) {
510
- return (0, $7oI3p$lodash.uniqBy)(results, (r)=>r.name).map((r)=>r.name + "=" + r.value).join("; ");
812
+ async function $2c9cc1b8a57118d9$export$c44c5fdef43f0941(params) {
813
+ const cookies = await (0, $adc20573c5fde3a5$export$e6d428437cf2cacb)(params, new (0, $5df4e8bfccec8ffc$export$2e2bcd8739ae039)());
814
+ if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
815
+ else throw new Error("Cookie not found");
511
816
  }
512
817
 
513
818
 
514
- async function $300d8b33187a203c$export$4d2e9997e2c23417(//
515
- { name: name , domain: domain }) {
516
- const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)({
517
- name: name,
518
- domain: domain
519
- }, new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)());
520
- if (Array.isArray(cookies) && cookies.length > 0) {
521
- const results = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)({
522
- name: name,
523
- domain: domain
524
- });
525
- const groupedByFile = (0, $7oI3p$lodash.groupBy)(results, (r)=>r.meta?.file);
526
- return Object.keys(groupedByFile).map((file)=>{
527
- const results = groupedByFile[file];
528
- return (0, $9c43c2ed82e63570$export$9abc0a414b0d8b8f)(results);
529
- });
530
- } else throw new Error("Cookie not found");
819
+
820
+
821
+ function $146fc82c45a46a88$export$9abc0a414b0d8b8f(results) {
822
+ // sort by name and expiry descending
823
+ // takes the latest expiry for each name
824
+ const orderedResults = (0, $cDXzb$lodash.orderBy)(results, [
825
+ "name",
826
+ "expiry"
827
+ ], [
828
+ "asc",
829
+ "desc"
830
+ ]);
831
+ return (0, $cDXzb$lodash.uniqBy)(orderedResults, (r)=>r.name).map((r)=>r.name + "=" + r.value).join("; ");
531
832
  }
532
833
 
533
834
 
534
835
 
535
836
 
837
+ async function $662fc5266a187ee3$export$a65902517ae87ba8(cookieSpec) {
838
+ const cookies = [];
839
+ if (Array.isArray(cookieSpec)) {
840
+ const results = await Promise.all(cookieSpec.map((cs)=>{
841
+ return (0, $adc20573c5fde3a5$export$e6d428437cf2cacb)(cs);
842
+ }));
843
+ for (const exportedCookie of results.flat())cookies.push(exportedCookie);
844
+ } else {
845
+ const singleQuery = await (0, $adc20573c5fde3a5$export$e6d428437cf2cacb)(cookieSpec);
846
+ cookies.push(...singleQuery);
847
+ }
848
+ return (0, $cDXzb$lodash.uniqBy)(cookies, JSON.stringify);
849
+ }
850
+
851
+
852
+ async function $3250e6c7c8746c6f$export$4d2e9997e2c23417(cookieSpec) {
853
+ const cookies = await (0, $662fc5266a187ee3$export$a65902517ae87ba8)(cookieSpec);
854
+ if (cookies.length == 0) throw new Error("Cookie not found");
855
+ const groupedByFile = (0, $cDXzb$lodash.groupBy)(cookies, (r)=>r.meta?.file);
856
+ return Object.keys(groupedByFile).map((file)=>{
857
+ const results = groupedByFile[file];
858
+ return (0, $146fc82c45a46a88$export$9abc0a414b0d8b8f)(results);
859
+ });
860
+ }
861
+
862
+
863
+
864
+
865
+ async function $01a8b57f5e2fbc3a$export$cfc0723de5712e57(cookieSpec) {
866
+ const cookies = await (0, $662fc5266a187ee3$export$a65902517ae87ba8)(cookieSpec);
867
+ if (cookies.length > 0) return (0, $146fc82c45a46a88$export$9abc0a414b0d8b8f)(cookies);
868
+ return "";
869
+ }
870
+
536
871
 
537
872
 
538
- async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}) {
873
+
874
+
875
+
876
+
877
+
878
+
879
+
880
+
881
+ function $2788377d65b088d2$export$f266452a5050185d(url) {
882
+ const url1 = typeof url == "string" ? new URL(url) : url;
883
+ const cookieSpecs = [];
884
+ const splits = url1.hostname.split(".");
885
+ const tld = splits.slice(-2).join(".");
886
+ const cookieSpec = {
887
+ name: "%",
888
+ domain: "%." + tld
889
+ };
890
+ cookieSpecs.push(cookieSpec);
891
+ const cookieSpec1 = {
892
+ name: "%",
893
+ domain: url1.hostname
894
+ };
895
+ cookieSpecs.push(cookieSpec1);
896
+ // const isWww = splits.slice(-3)[0] === "www";
897
+ const cookieSpec2 = {
898
+ name: "%",
899
+ domain: tld
900
+ };
901
+ cookieSpecs.push(cookieSpec2);
902
+ return (0, $cDXzb$lodash.uniqBy)(cookieSpecs, JSON.stringify);
903
+ }
904
+
905
+
906
+ const $9784c2ab321f9dab$var$userAgent = new (0, ($parcel$interopDefault($cDXzb$useragents)))().toString();
907
+ async function $9784c2ab321f9dab$export$b24a545a0b39f491(url, options = {}, fetch = (0, $cDXzb$crossfetch.fetch), originalRequest) {
908
+ const originalRequest1 = originalRequest || {
909
+ url: url,
910
+ options: options
911
+ };
912
+ const headers = {
913
+ "User-Agent": $9784c2ab321f9dab$var$userAgent
914
+ };
539
915
  const defaultOptions = {
540
- headers: {
541
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
542
- },
916
+ headers: headers,
543
917
  redirect: "manual"
544
918
  };
545
919
  const url2 = `${url}`;
546
920
  const url1 = new URL(url2);
547
- const domain = url1.hostname.replace(/^.*(\.\w+\.\w+)$/, (match, p1)=>{
548
- return `%${p1}`;
549
- });
550
- const cookies = await (0, $300d8b33187a203c$export$4d2e9997e2c23417)({
551
- name: "%",
552
- domain: domain
553
- }).catch(()=>[]);
554
- const cookie = cookies.pop();
555
- const newOptions1 = (0, $7oI3p$lodash.merge)(defaultOptions, options, {
556
- headers: {
557
- Cookie: cookie
558
- }
559
- });
921
+ const cookieSpecs = (0, $2788377d65b088d2$export$f266452a5050185d)(url1);
922
+ headers["Cookie"] = await (0, $01a8b57f5e2fbc3a$export$cfc0723de5712e57)(cookieSpecs).catch(()=>"");
923
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b)["dump-request-headers"]) {
924
+ console.log((0, $cDXzb$colorette.redBright)("Request URL:"), url1.href);
925
+ console.log((0, $cDXzb$colorette.blue)("Request headers:"), headers);
926
+ }
927
+ const newOptions1 = (0, $cDXzb$lodash.merge)(defaultOptions, {
928
+ headers: headers
929
+ }, options);
560
930
  try {
561
- const res = await (0, $7oI3p$crossfetch.fetch)(url2, newOptions1);
562
- const newUrl = res.headers.get("location");
563
- if (res.redirected || newUrl && newUrl !== url2) return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(newUrl, newOptions1);
931
+ const res = await fetch(url1, newOptions1);
932
+ const headers1 = [];
933
+ res.headers.forEach((value, key)=>{
934
+ headers1.push([
935
+ key,
936
+ value
937
+ ]);
938
+ });
939
+ for (const [key, value] of headers1)if (key === "set-cookie") {
940
+ const cookieJar1 = await (0, $14bfa2612c55b48d$export$eced8873dedbb4c0);
941
+ await cookieJar1.setCookie(value, url2);
942
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log((0, $cDXzb$colorette.blue)(`Set-Cookie:`), (0, $cDXzb$colorette.yellow)(value), (0, $cDXzb$colorette.yellow)(url2));
943
+ }
944
+ const newUrl = res.headers.get("location") ?? res.url;
945
+ // const sameHost = new URL(newUrl).host === url1.host;
946
+ if (res.status == 301 || res.status == 302) // follow the redirect
947
+ {
948
+ if (newUrl && newUrl !== url2) {
949
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose || (0, $7b83c0e89cc28a81$export$c348dfaf65040d9b)["dump-response-headers"]) console.log((0, $cDXzb$colorette.blue)(`Redirected to `), (0, $cDXzb$colorette.yellow)(newUrl));
950
+ return $9784c2ab321f9dab$export$b24a545a0b39f491(//
951
+ newUrl, newOptions1, fetch, originalRequest1);
952
+ }
953
+ }
954
+ if (res.status == 303 && newUrl && newUrl !== url2) {
955
+ // follow the redirect with GET
956
+ let newOptions2 = {};
957
+ switch(newOptions1.method){
958
+ case "POST":
959
+ case "PUT":
960
+ case "DELETE":
961
+ (0, $cDXzb$lodash.merge)(newOptions2, newOptions1, {
962
+ method: "GET"
963
+ });
964
+ newOptions2.body = undefined; // TODO: is this needed?
965
+ break;
966
+ case "HEAD":
967
+ case "GET":
968
+ (0, $cDXzb$lodash.merge)(newOptions2, newOptions1);
969
+ newOptions2.body = undefined; // TODO: is this needed?
970
+ break;
971
+ default:
972
+ (0, $cDXzb$lodash.merge)(newOptions2, newOptions1);
973
+ break;
974
+ }
975
+ if ((0, $7b83c0e89cc28a81$export$c348dfaf65040d9b).verbose) console.log((0, $cDXzb$colorette.blue)(`Redirected to `), (0, $cDXzb$colorette.yellow)(newUrl));
976
+ return $9784c2ab321f9dab$export$b24a545a0b39f491(//
977
+ newUrl, newOptions2, fetch, originalRequest1);
978
+ }
564
979
  const arrayBuffer1 = res.arrayBuffer();
565
- const arrayBuffer = async ()=>arrayBuffer1;
566
- const buffer = async ()=>arrayBuffer().then(Buffer.from);
567
- const text = async ()=>buffer().then((buffer)=>buffer.toString("utf8"));
568
- const json = async ()=>text().then((0, ($parcel$interopDefault($7oI3p$destr))));
569
- const formData = async ()=>text().then((text)=>new URLSearchParams(text));
980
+ async function arrayBuffer() {
981
+ return arrayBuffer1;
982
+ }
983
+ async function buffer() {
984
+ return arrayBuffer().then(Buffer.from);
985
+ }
986
+ async function text() {
987
+ return buffer().then((buffer)=>buffer.toString("utf8"));
988
+ }
989
+ async function json() {
990
+ return text().then((text)=>(0, ($parcel$interopDefault($cDXzb$destr)))(text));
991
+ }
992
+ async function formData() {
993
+ const urlSearchParams = await text().then((text)=>new URLSearchParams(text));
994
+ const formData = new FormData();
995
+ for (const [key, value] of urlSearchParams.entries())formData.append(key, value);
996
+ return formData;
997
+ }
998
+ const res1 = res;
570
999
  const source2 = {
571
- status: res.status,
572
- statusText: res.statusText,
573
- headers: res.headers,
574
1000
  arrayBuffer: arrayBuffer,
575
- buffer: buffer,
576
1001
  text: text,
577
1002
  json: json,
1003
+ buffer: buffer,
578
1004
  formData: formData
579
1005
  };
580
- return (0, $7oI3p$lodash.merge)({}, res, source2);
1006
+ return (0, $cDXzb$lodash.merge)(res1, source2);
581
1007
  } catch (e) {
582
1008
  throw e;
583
1009
  }
584
1010
  }
585
1011
 
586
1012
 
587
- var $d5b6386167d289d2$exports = {};
1013
+ var $36f7eea49875091b$exports = {};
588
1014
 
589
1015
 
590
- var $3d7e27b54f670f46$exports = {};
1016
+ var $80f8b323ce8fd8b7$exports = {};
591
1017
 
592
1018
 
593
- var $6c197c88880e045c$exports = {};
1019
+ var $bf28d13de48682c5$exports = {};
594
1020
 
595
1021
 
596
- async function $cd1ba0160120c006$export$4be65e66cfa2648a(params) {
597
- const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)());
598
- if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
599
- else throw new Error("Cookie not found");
600
- }
601
- async function $cd1ba0160120c006$export$c44c5fdef43f0941(params) {
602
- const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $7bb7da9a77b2fd99$export$2e2bcd8739ae039)());
603
- if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
604
- else throw new Error("Cookie not found");
605
- }
606
- async function $cd1ba0160120c006$export$e5637297e9eb6f2e(params) {
607
- const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(params, new (0, $269fe42bfd555305$export$2e2bcd8739ae039)());
608
- if (Array.isArray(cookies) && cookies.length > 0) return cookies.find((cookie)=>cookie != null);
609
- else throw new Error("Cookie not found");
610
- }
611
- $parcel$exportWildcard(module.exports, $d5b6386167d289d2$exports);
612
- $parcel$exportWildcard(module.exports, $3d7e27b54f670f46$exports);
613
- $parcel$exportWildcard(module.exports, $6c197c88880e045c$exports);
1022
+ $parcel$exportWildcard(module.exports, $36f7eea49875091b$exports);
1023
+ $parcel$exportWildcard(module.exports, $80f8b323ce8fd8b7$exports);
1024
+ $parcel$exportWildcard(module.exports, $bf28d13de48682c5$exports);
614
1025
 
615
1026
 
616
1027
  //# sourceMappingURL=index.js.map