@mherod/get-cookie 2.0.0-rc.7 → 2.0.0-rc.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.
- package/dist/index.js +132 -55
- package/package.json +2 -2
- package/src/CookieRow.ts +1 -0
- package/src/ExportedCookie.ts +1 -0
- package/src/browsers/ChromeCookieQueryStrategy.ts +61 -4
- package/src/browsers/CookieStoreQueryStrategy.ts +2 -1
- package/src/doSqliteQuery1.ts +1 -6
- package/src/doSqliteQuery1Params.ts +7 -0
- package/src/fetchWithCookies.ts +12 -9
- package/src/findAllFiles.ts +0 -1
- package/src/getMergedRenderedCookies.ts +25 -0
- package/src/index.ts +2 -0
- package/src/resultsRendered.ts +6 -3
- package/src/utils.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -6,8 +6,8 @@ var $7oI3p$colorette = require("colorette");
|
|
|
6
6
|
var $7oI3p$fs = require("fs");
|
|
7
7
|
var $7oI3p$crypto = require("crypto");
|
|
8
8
|
var $7oI3p$path = require("path");
|
|
9
|
-
var $7oI3p$child_process = require("child_process");
|
|
10
9
|
var $7oI3p$sqlite3 = require("sqlite3");
|
|
10
|
+
var $7oI3p$child_process = require("child_process");
|
|
11
11
|
var $7oI3p$toughcookie = require("tough-cookie");
|
|
12
12
|
var $7oI3p$toughcookiefilestore = require("tough-cookie-file-store");
|
|
13
13
|
var $7oI3p$jsonwebtoken = require("jsonwebtoken");
|
|
@@ -41,6 +41,7 @@ function $parcel$interopDefault(a) {
|
|
|
41
41
|
$parcel$export(module.exports, "getCookie", () => $8481e2034946cc4b$export$4be65e66cfa2648a);
|
|
42
42
|
$parcel$export(module.exports, "getChromeCookie", () => $1a92ef2038b55530$export$e5637297e9eb6f2e);
|
|
43
43
|
$parcel$export(module.exports, "getFirefoxCookie", () => $f9b70200901ad17d$export$c44c5fdef43f0941);
|
|
44
|
+
$parcel$export(module.exports, "getMergedRenderedCookies", () => $4ffeaeb7bb3c0319$export$cfc0723de5712e57);
|
|
44
45
|
$parcel$export(module.exports, "getGroupedRenderedCookies", () => $300d8b33187a203c$export$4d2e9997e2c23417);
|
|
45
46
|
$parcel$export(module.exports, "fetchWithCookies", () => $cfc07ae4aa2c7e44$export$b24a545a0b39f491);
|
|
46
47
|
|
|
@@ -125,46 +126,6 @@ async function $e62c2c56eb720f29$export$2c9faf86071156ae({ path: path , name: na
|
|
|
125
126
|
|
|
126
127
|
|
|
127
128
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
async function $a085b524d8ee9fce$export$f19f611d1fa7c6f3({ file: file , sql: sql , rowTransform: rowTransform }) {
|
|
132
|
-
if (!file || file && !$7oI3p$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
133
|
-
const db = new $7oI3p$sqlite3.Database(file);
|
|
134
|
-
return new Promise((resolve, reject)=>{
|
|
135
|
-
db.all(sql, (err, rows)=>{
|
|
136
|
-
if (err) {
|
|
137
|
-
reject(err);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const rows1 = rows;
|
|
141
|
-
if (rows1 == null || rows1.length === 0) {
|
|
142
|
-
resolve([]);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (Array.isArray(rows1)) {
|
|
146
|
-
const cookieRows = rows1.map((row)=>{
|
|
147
|
-
const newVar = {
|
|
148
|
-
meta: {
|
|
149
|
-
file: file
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
const cookieRow = rowTransform(row);
|
|
153
|
-
return (0, $7oI3p$lodash.merge)(newVar, cookieRow);
|
|
154
|
-
});
|
|
155
|
-
resolve(cookieRows);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
159
|
-
resolve([
|
|
160
|
-
rows1
|
|
161
|
-
]);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
129
|
function $af69dfb8766652d8$export$bc926c43858bd3cb(obj) {
|
|
169
130
|
return obj.domain !== undefined && obj.name !== undefined && obj.value !== undefined;
|
|
170
131
|
}
|
|
@@ -184,6 +145,8 @@ function $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb(s) {
|
|
|
184
145
|
|
|
185
146
|
|
|
186
147
|
|
|
148
|
+
|
|
149
|
+
|
|
187
150
|
class $269fe42bfd555305$export$2e2bcd8739ae039 {
|
|
188
151
|
browserName = "Chrome";
|
|
189
152
|
async queryCookies(name, domain) {
|
|
@@ -240,12 +203,17 @@ async function $269fe42bfd555305$var$getChromeCookies({ name: name , domain: dom
|
|
|
240
203
|
const decryptedValue = await $269fe42bfd555305$var$decryptValue(password, encryptedValue);
|
|
241
204
|
const meta = {};
|
|
242
205
|
(0, $7oI3p$lodash.merge)(meta, cookieRow.meta ?? {});
|
|
243
|
-
|
|
206
|
+
const exportedCookie = {
|
|
244
207
|
domain: cookieRow.domain,
|
|
245
208
|
name: cookieRow.name,
|
|
246
209
|
value: decryptedValue,
|
|
247
210
|
meta: meta
|
|
248
211
|
};
|
|
212
|
+
const expiry = cookieRow.expiry;
|
|
213
|
+
if (expiry) (0, $7oI3p$lodash.merge)(exportedCookie, {
|
|
214
|
+
expiry: new Date(expiry)
|
|
215
|
+
});
|
|
216
|
+
return exportedCookie;
|
|
249
217
|
});
|
|
250
218
|
const results = (await Promise.all(decrypted)).filter((0, $d66f40b581ba8bfa$export$963c8d651337e4a4));
|
|
251
219
|
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("results", results);
|
|
@@ -260,7 +228,8 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
|
|
|
260
228
|
}
|
|
261
229
|
let sql;
|
|
262
230
|
//language=SQL
|
|
263
|
-
sql = "SELECT
|
|
231
|
+
sql = "SELECT * FROM cookies";
|
|
232
|
+
// sql = "SELECT encrypted_value, name, host_key FROM cookies";
|
|
264
233
|
const wildcardRegexp = /^([*%])$/i;
|
|
265
234
|
const specifiedName = name.match(wildcardRegexp) == null;
|
|
266
235
|
const specifiedDomain = domain.match(wildcardRegexp) == null;
|
|
@@ -279,15 +248,18 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
|
|
|
279
248
|
sql += `host_key LIKE '${sqlEmbedDomain}';`;
|
|
280
249
|
}
|
|
281
250
|
}
|
|
282
|
-
const sqliteQuery1 = await
|
|
251
|
+
const sqliteQuery1 = await $269fe42bfd555305$export$bd52b72df8d0d261({
|
|
283
252
|
file: file,
|
|
284
253
|
sql: sql,
|
|
285
254
|
rowTransform: (row)=>{
|
|
286
|
-
|
|
255
|
+
const cookieRow = {
|
|
256
|
+
expiry: (row["expires_utc"] / 1000000 - 11644473600) * 1000,
|
|
287
257
|
domain: row["host_key"],
|
|
288
258
|
name: row["name"],
|
|
289
259
|
value: row["encrypted_value"]
|
|
290
260
|
};
|
|
261
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("CookieRow", cookieRow);
|
|
262
|
+
return cookieRow;
|
|
291
263
|
}
|
|
292
264
|
});
|
|
293
265
|
return sqliteQuery1.filter((row)=>{
|
|
@@ -352,6 +324,42 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
352
324
|
});
|
|
353
325
|
});
|
|
354
326
|
}
|
|
327
|
+
async function $269fe42bfd555305$export$bd52b72df8d0d261({ file: file , sql: sql , rowTransform: rowTransform }) {
|
|
328
|
+
if (!file || file && !(0, ($parcel$interopDefault($7oI3p$fs))).existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
329
|
+
const db = new $7oI3p$sqlite3.Database(file);
|
|
330
|
+
return new Promise((resolve, reject)=>{
|
|
331
|
+
db.all(sql, (err, rows)=>{
|
|
332
|
+
if (err) {
|
|
333
|
+
reject(err);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const rows1 = rows;
|
|
337
|
+
if (rows1 == null || rows1.length === 0) {
|
|
338
|
+
resolve([]);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (Array.isArray(rows1)) {
|
|
342
|
+
const cookieRows = rows1.map((row)=>{
|
|
343
|
+
const newVar = {
|
|
344
|
+
meta: {
|
|
345
|
+
file: file
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
const cookieRow = rowTransform(row);
|
|
349
|
+
return (0, $7oI3p$lodash.merge)(newVar, cookieRow);
|
|
350
|
+
});
|
|
351
|
+
resolve(cookieRows);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
355
|
+
resolve([
|
|
356
|
+
rows1
|
|
357
|
+
]);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
|
|
355
363
|
|
|
356
364
|
|
|
357
365
|
|
|
@@ -359,6 +367,43 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
359
367
|
|
|
360
368
|
|
|
361
369
|
|
|
370
|
+
|
|
371
|
+
async function $a085b524d8ee9fce$export$f19f611d1fa7c6f3({ file: file , sql: sql , rowTransform: rowTransform }) {
|
|
372
|
+
if (!file || file && !$7oI3p$fs.existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
373
|
+
const db = new $7oI3p$sqlite3.Database(file);
|
|
374
|
+
return new Promise((resolve, reject)=>{
|
|
375
|
+
db.all(sql, (err, rows)=>{
|
|
376
|
+
if (err) {
|
|
377
|
+
reject(err);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const rows1 = rows;
|
|
381
|
+
if (rows1 == null || rows1.length === 0) {
|
|
382
|
+
resolve([]);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (Array.isArray(rows1)) {
|
|
386
|
+
const cookieRows = rows1.map((row)=>{
|
|
387
|
+
const newVar = {
|
|
388
|
+
meta: {
|
|
389
|
+
file: file
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
const cookieRow = rowTransform(row);
|
|
393
|
+
return (0, $7oI3p$lodash.merge)(newVar, cookieRow);
|
|
394
|
+
});
|
|
395
|
+
resolve(cookieRows);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
399
|
+
resolve([
|
|
400
|
+
rows1
|
|
401
|
+
]);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
|
|
362
407
|
function $b744d19cc39f964e$export$da22813e5a2ec500({ name: name , domain: domain }) {
|
|
363
408
|
const wildcardRegexp = /^([*%])$/i;
|
|
364
409
|
return {
|
|
@@ -496,8 +541,9 @@ class $e4efb16e005540de$export$2e2bcd8739ae039 {
|
|
|
496
541
|
domain: cookie.domain ?? cookieSpec.domain,
|
|
497
542
|
name: cookie.key ?? cookieSpec.name,
|
|
498
543
|
value: cookie.value,
|
|
544
|
+
expiry: cookie.expires ?? Infinity,
|
|
499
545
|
meta: {
|
|
500
|
-
file: "
|
|
546
|
+
file: "tough-cookie"
|
|
501
547
|
}
|
|
502
548
|
};
|
|
503
549
|
}
|
|
@@ -642,7 +688,16 @@ async function $f9b70200901ad17d$export$c44c5fdef43f0941(params) {
|
|
|
642
688
|
|
|
643
689
|
|
|
644
690
|
function $9c43c2ed82e63570$export$9abc0a414b0d8b8f(results) {
|
|
645
|
-
|
|
691
|
+
// sort by name and expiry descending
|
|
692
|
+
// takes the latest expiry for each name
|
|
693
|
+
const orderedResults = (0, $7oI3p$lodash.orderBy)(results, [
|
|
694
|
+
"name",
|
|
695
|
+
"expiry"
|
|
696
|
+
], [
|
|
697
|
+
"asc",
|
|
698
|
+
"desc"
|
|
699
|
+
]);
|
|
700
|
+
return (0, $7oI3p$lodash.uniqBy)(orderedResults, (r)=>r.name).map((r)=>r.name + "=" + r.value).join("; ");
|
|
646
701
|
}
|
|
647
702
|
|
|
648
703
|
|
|
@@ -668,6 +723,23 @@ async function $300d8b33187a203c$export$4d2e9997e2c23417({ name: name , domain:
|
|
|
668
723
|
|
|
669
724
|
|
|
670
725
|
|
|
726
|
+
async function $4ffeaeb7bb3c0319$export$cfc0723de5712e57({ name: name , domain: domain }) {
|
|
727
|
+
const cookies = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)({
|
|
728
|
+
name: name,
|
|
729
|
+
domain: domain
|
|
730
|
+
}, new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)());
|
|
731
|
+
if (cookies.length == 0) throw new Error("Cookie not found");
|
|
732
|
+
const results = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)({
|
|
733
|
+
name: name,
|
|
734
|
+
domain: domain
|
|
735
|
+
});
|
|
736
|
+
return (0, $9c43c2ed82e63570$export$9abc0a414b0d8b8f)(results);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
671
743
|
|
|
672
744
|
|
|
673
745
|
|
|
@@ -689,23 +761,28 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
|
|
|
689
761
|
name: "%",
|
|
690
762
|
domain: domain
|
|
691
763
|
};
|
|
692
|
-
const cookies = await (
|
|
693
|
-
|
|
764
|
+
// const cookies: string[] = await getGroupedRenderedCookies(cookieSpec).catch(
|
|
765
|
+
// () => []
|
|
766
|
+
// );
|
|
767
|
+
// const cookie = cookies.pop();
|
|
768
|
+
const cookie = await (0, $4ffeaeb7bb3c0319$export$cfc0723de5712e57)(cookieSpec).catch(()=>"");
|
|
769
|
+
const headers = {};
|
|
770
|
+
if (cookie.length > 0) (0, $7oI3p$lodash.merge)(headers, {
|
|
771
|
+
Cookie: cookie
|
|
772
|
+
});
|
|
694
773
|
const newOptions1 = (0, $7oI3p$lodash.merge)(defaultOptions, options, {
|
|
695
|
-
headers:
|
|
696
|
-
Cookie: cookie
|
|
697
|
-
}
|
|
774
|
+
headers: headers
|
|
698
775
|
});
|
|
699
776
|
try {
|
|
700
777
|
const res = await fetch(url2, newOptions1);
|
|
701
|
-
const
|
|
778
|
+
const headers1 = [];
|
|
702
779
|
res.headers.forEach((value, key)=>{
|
|
703
|
-
|
|
780
|
+
headers1.push([
|
|
704
781
|
key,
|
|
705
782
|
value
|
|
706
783
|
]);
|
|
707
784
|
});
|
|
708
|
-
for (const [key, value] of
|
|
785
|
+
for (const [key, value] of headers1)if (key === "set-cookie") {
|
|
709
786
|
await (0, $53a3bcc99a05dfcf$export$928a906645f9d018).setCookie(value, url2);
|
|
710
787
|
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Set-Cookie: ${(0, $7oI3p$colorette.yellow)(value)} ${(0, $7oI3p$colorette.yellow)(url2)}`));
|
|
711
788
|
// const cookie = tough.parse(value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mherod/get-cookie",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.9",
|
|
4
4
|
"description": "Node.js module for querying a local user's Chrome cookie",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"bin": "dist/cli.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"clean": "git clean -
|
|
14
|
+
"clean": "git clean -fdX && rm -rf node_modules dist && yarn install",
|
|
15
15
|
"build": "parcel build",
|
|
16
16
|
"prepare": "npm run build && npm run prettier",
|
|
17
17
|
"test": "jest",
|
package/src/CookieRow.ts
CHANGED
package/src/ExportedCookie.ts
CHANGED
|
@@ -13,6 +13,9 @@ import CookieRow from "../CookieRow";
|
|
|
13
13
|
import ExportedCookie from "../ExportedCookie";
|
|
14
14
|
import { stringToRegex } from "../StringToRegex";
|
|
15
15
|
import { parsedArgs } from "../argv";
|
|
16
|
+
import fs from "fs";
|
|
17
|
+
import * as sqlite3 from "sqlite3";
|
|
18
|
+
import { DoSqliteQuery1Params } from "../doSqliteQuery1Params";
|
|
16
19
|
|
|
17
20
|
export default class ChromeCookieQueryStrategy implements CookieQueryStrategy {
|
|
18
21
|
browserName = "Chrome";
|
|
@@ -103,12 +106,19 @@ Promise<ExportedCookie[]> {
|
|
|
103
106
|
const decryptedValue = await decryptValue(password, encryptedValue);
|
|
104
107
|
const meta = {};
|
|
105
108
|
merge(meta, cookieRow.meta ?? {});
|
|
106
|
-
|
|
109
|
+
const exportedCookie: ExportedCookie = {
|
|
107
110
|
domain: cookieRow.domain,
|
|
108
111
|
name: cookieRow.name,
|
|
109
112
|
value: decryptedValue,
|
|
110
113
|
meta: meta,
|
|
111
114
|
};
|
|
115
|
+
const expiry = cookieRow.expiry;
|
|
116
|
+
if (expiry) {
|
|
117
|
+
merge(exportedCookie, {
|
|
118
|
+
expiry: new Date(expiry),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return exportedCookie;
|
|
112
122
|
});
|
|
113
123
|
const results: ExportedCookie[] = (await Promise.all(decrypted)).filter(
|
|
114
124
|
isExportedCookie
|
|
@@ -146,7 +156,8 @@ async function getEncryptedChromeCookie({
|
|
|
146
156
|
}
|
|
147
157
|
let sql;
|
|
148
158
|
//language=SQL
|
|
149
|
-
sql = "SELECT
|
|
159
|
+
sql = "SELECT * FROM cookies";
|
|
160
|
+
// sql = "SELECT encrypted_value, name, host_key FROM cookies";
|
|
150
161
|
|
|
151
162
|
const wildcardRegexp = /^([*%])$/i;
|
|
152
163
|
const specifiedName = name.match(wildcardRegexp) == null;
|
|
@@ -168,15 +179,20 @@ async function getEncryptedChromeCookie({
|
|
|
168
179
|
sql += `host_key LIKE '${sqlEmbedDomain}';`;
|
|
169
180
|
}
|
|
170
181
|
}
|
|
171
|
-
const sqliteQuery1: CookieRow[] = await
|
|
182
|
+
const sqliteQuery1: CookieRow[] = await doChromeSqliteQuery1({
|
|
172
183
|
file: file,
|
|
173
184
|
sql: sql,
|
|
174
185
|
rowTransform: (row) => {
|
|
175
|
-
|
|
186
|
+
const cookieRow = {
|
|
187
|
+
expiry: (row["expires_utc"] / 1000000 - 11644473600) * 1000,
|
|
176
188
|
domain: row["host_key"],
|
|
177
189
|
name: row["name"],
|
|
178
190
|
value: row["encrypted_value"],
|
|
179
191
|
};
|
|
192
|
+
if (parsedArgs.verbose) {
|
|
193
|
+
console.log("CookieRow", cookieRow);
|
|
194
|
+
}
|
|
195
|
+
return cookieRow;
|
|
180
196
|
},
|
|
181
197
|
});
|
|
182
198
|
return sqliteQuery1.filter((row) => {
|
|
@@ -284,3 +300,44 @@ async function decrypt(
|
|
|
284
300
|
});
|
|
285
301
|
});
|
|
286
302
|
}
|
|
303
|
+
|
|
304
|
+
export async function doChromeSqliteQuery1({
|
|
305
|
+
file,
|
|
306
|
+
sql,
|
|
307
|
+
rowTransform,
|
|
308
|
+
}: DoSqliteQuery1Params): Promise<CookieRow[]> {
|
|
309
|
+
if (!file || (file && !fs.existsSync(file))) {
|
|
310
|
+
throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
311
|
+
}
|
|
312
|
+
const db = new sqlite3.Database(file);
|
|
313
|
+
return new Promise((resolve, reject) => {
|
|
314
|
+
db.all(sql, (err: Error, rows: any[]) => {
|
|
315
|
+
if (err) {
|
|
316
|
+
reject(err);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const rows1: any[] = rows;
|
|
320
|
+
if (rows1 == null || rows1.length === 0) {
|
|
321
|
+
resolve([]);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (Array.isArray(rows1)) {
|
|
325
|
+
const cookieRows: CookieRow[] = rows1.map((row: any) => {
|
|
326
|
+
const newVar = {
|
|
327
|
+
meta: {
|
|
328
|
+
file: file,
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
const cookieRow: CookieRow = rowTransform(row);
|
|
332
|
+
return merge(newVar, cookieRow);
|
|
333
|
+
});
|
|
334
|
+
resolve(cookieRows);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (parsedArgs.verbose) {
|
|
338
|
+
console.log(`doSqliteQuery1: rows ${JSON.stringify(rows1)}`);
|
|
339
|
+
}
|
|
340
|
+
resolve([rows1]);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
}
|
|
@@ -57,8 +57,9 @@ export default class CookieStoreQueryStrategy implements CookieQueryStrategy {
|
|
|
57
57
|
domain: cookie.domain ?? cookieSpec.domain,
|
|
58
58
|
name: cookie.key ?? cookieSpec.name,
|
|
59
59
|
value: cookie.value,
|
|
60
|
+
expiry: cookie.expires ?? Infinity,
|
|
60
61
|
meta: {
|
|
61
|
-
file: "
|
|
62
|
+
file: "tough-cookie",
|
|
62
63
|
},
|
|
63
64
|
};
|
|
64
65
|
}
|
package/src/doSqliteQuery1.ts
CHANGED
|
@@ -3,12 +3,7 @@ import * as sqlite3 from "sqlite3";
|
|
|
3
3
|
import CookieRow from "./CookieRow";
|
|
4
4
|
import { merge } from "lodash";
|
|
5
5
|
import { parsedArgs } from "./argv";
|
|
6
|
-
|
|
7
|
-
interface DoSqliteQuery1Params {
|
|
8
|
-
file: string;
|
|
9
|
-
sql: string;
|
|
10
|
-
rowTransform: (row: any) => CookieRow;
|
|
11
|
-
}
|
|
6
|
+
import { DoSqliteQuery1Params } from "./doSqliteQuery1Params";
|
|
12
7
|
|
|
13
8
|
export async function doSqliteQuery1({
|
|
14
9
|
file,
|
package/src/fetchWithCookies.ts
CHANGED
|
@@ -5,11 +5,11 @@ import { merge } from "lodash";
|
|
|
5
5
|
// noinspection SpellCheckingInspection
|
|
6
6
|
import destr from "destr";
|
|
7
7
|
import CookieSpec from "./CookieSpec";
|
|
8
|
-
import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
|
|
9
8
|
import { cookieJar } from "./CookieStore";
|
|
10
9
|
import UserAgent from "user-agents";
|
|
11
10
|
import { parsedArgs } from "./argv";
|
|
12
11
|
import { blue, yellow } from "colorette";
|
|
12
|
+
import { getMergedRenderedCookies } from "./getMergedRenderedCookies";
|
|
13
13
|
|
|
14
14
|
export async function fetchWithCookies(
|
|
15
15
|
url: RequestInfo | URL,
|
|
@@ -31,15 +31,18 @@ export async function fetchWithCookies(
|
|
|
31
31
|
name: "%",
|
|
32
32
|
domain: domain,
|
|
33
33
|
};
|
|
34
|
-
const cookies: string[] = await getGroupedRenderedCookies(cookieSpec).catch(
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
const cookie = cookies.pop();
|
|
38
|
-
const
|
|
39
|
-
|
|
34
|
+
// const cookies: string[] = await getGroupedRenderedCookies(cookieSpec).catch(
|
|
35
|
+
// () => []
|
|
36
|
+
// );
|
|
37
|
+
// const cookie = cookies.pop();
|
|
38
|
+
const cookie = await getMergedRenderedCookies(cookieSpec).catch(() => "");
|
|
39
|
+
const headers = {};
|
|
40
|
+
if (cookie.length > 0) {
|
|
41
|
+
merge(headers, {
|
|
40
42
|
Cookie: cookie,
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const newOptions1: RequestInit = merge(defaultOptions, options, { headers });
|
|
43
46
|
try {
|
|
44
47
|
const res: Response = await fetch(url2, newOptions1);
|
|
45
48
|
const headers: [string, string][] = [];
|
package/src/findAllFiles.ts
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { groupBy } from "lodash";
|
|
2
|
+
import { queryCookies } from "./queryCookies";
|
|
3
|
+
import { resultsRendered } from "./resultsRendered";
|
|
4
|
+
import CompositeCookieQueryStrategy from "./browsers/CompositeCookieQueryStrategy";
|
|
5
|
+
import CookieSpec from "./CookieSpec";
|
|
6
|
+
import ExportedCookie from "./ExportedCookie";
|
|
7
|
+
|
|
8
|
+
export async function getMergedRenderedCookies({
|
|
9
|
+
name,
|
|
10
|
+
domain,
|
|
11
|
+
}: CookieSpec): Promise<string> {
|
|
12
|
+
const cookies: ExportedCookie[] = await queryCookies(
|
|
13
|
+
{
|
|
14
|
+
name,
|
|
15
|
+
domain,
|
|
16
|
+
},
|
|
17
|
+
new CompositeCookieQueryStrategy()
|
|
18
|
+
//
|
|
19
|
+
);
|
|
20
|
+
if (cookies.length == 0) {
|
|
21
|
+
throw new Error("Cookie not found");
|
|
22
|
+
}
|
|
23
|
+
const results: ExportedCookie[] = await queryCookies({ name, domain });
|
|
24
|
+
return resultsRendered(results);
|
|
25
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,12 +5,14 @@ import { getCookie } from "./getCookie";
|
|
|
5
5
|
import { getChromeCookie } from "./getChromeCookie";
|
|
6
6
|
import { getFirefoxCookie } from "./getFirefoxCookie";
|
|
7
7
|
import { getGroupedRenderedCookies } from "./getGroupedRenderedCookies";
|
|
8
|
+
import { getMergedRenderedCookies } from "./getMergedRenderedCookies";
|
|
8
9
|
import { fetchWithCookies } from "./fetchWithCookies";
|
|
9
10
|
|
|
10
11
|
export {
|
|
11
12
|
getCookie,
|
|
12
13
|
getChromeCookie,
|
|
13
14
|
getFirefoxCookie,
|
|
15
|
+
getMergedRenderedCookies,
|
|
14
16
|
getGroupedRenderedCookies,
|
|
15
17
|
fetchWithCookies,
|
|
16
18
|
//
|
package/src/resultsRendered.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { uniqBy } from "lodash";
|
|
1
|
+
import { orderBy, uniqBy } from "lodash";
|
|
2
2
|
import ExportedCookie from "./ExportedCookie";
|
|
3
3
|
|
|
4
4
|
export function resultsRendered(results: ExportedCookie[]) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// sort by name and expiry descending
|
|
6
|
+
// takes the latest expiry for each name
|
|
7
|
+
const orderedResults = orderBy(results, ["name", "expiry"], ["asc", "desc"]);
|
|
8
|
+
return uniqBy(orderedResults, (r: ExportedCookie) => r.name)
|
|
9
|
+
.map((r: ExportedCookie) => r.name + "=" + r.value)
|
|
7
10
|
.join("; ");
|
|
8
11
|
}
|
package/src/utils.ts
CHANGED