@mherod/get-cookie 2.0.0-beta.8 → 2.0.0-beta.9

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