@mherod/get-cookie 2.0.0-rc.10 → 2.0.0-rc.11
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 +71 -46
- package/package.json +3 -2
- package/src/CookieSpec.ts +2 -0
- package/src/CookieStore.ts +1 -0
- package/src/browsers/ChromeCookieQueryStrategy.ts +30 -18
- package/src/browsers/CookieQueryStrategy.ts +1 -0
- package/src/browsers/CookieStoreQueryStrategy.ts +2 -2
- package/src/cli.ts +25 -10
- package/src/comboQueryCookieSpec.ts +21 -0
- package/src/cookieSpecsFromUrl.ts +26 -0
- package/src/doSqliteQuery1Params.ts +1 -0
- package/src/fetchWithCookies.ts +11 -17
- package/src/getGroupedRenderedCookies.ts +7 -17
- package/src/getMergedRenderedCookies.ts +9 -20
package/dist/index.js
CHANGED
|
@@ -146,7 +146,6 @@ function $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb(s) {
|
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
|
|
149
|
-
|
|
150
149
|
class $269fe42bfd555305$export$2e2bcd8739ae039 {
|
|
151
150
|
browserName = "Chrome";
|
|
152
151
|
async queryCookies(name, domain) {
|
|
@@ -210,9 +209,12 @@ async function $269fe42bfd555305$var$getChromeCookies({ name: name , domain: dom
|
|
|
210
209
|
meta: meta
|
|
211
210
|
};
|
|
212
211
|
const expiry = cookieRow.expiry;
|
|
213
|
-
|
|
212
|
+
const mergeExpiry = expiry != null && expiry > 0 ? {
|
|
214
213
|
expiry: new Date(expiry)
|
|
215
|
-
}
|
|
214
|
+
} : {
|
|
215
|
+
expiry: "Infinity"
|
|
216
|
+
};
|
|
217
|
+
(0, $7oI3p$lodash.merge)(exportedCookie, mergeExpiry);
|
|
216
218
|
return exportedCookie;
|
|
217
219
|
});
|
|
218
220
|
const results = (await Promise.all(decrypted)).filter((0, $d66f40b581ba8bfa$export$963c8d651337e4a4));
|
|
@@ -248,9 +250,14 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
|
|
|
248
250
|
sql += `host_key LIKE '${sqlEmbedDomain}';`;
|
|
249
251
|
}
|
|
250
252
|
}
|
|
253
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log("sql", sql);
|
|
254
|
+
const domainRegexp = (0, $68c0ed99fadee6ca$export$4eadcf0bf35a2ddb)(domain);
|
|
251
255
|
const sqliteQuery1 = await $269fe42bfd555305$export$bd52b72df8d0d261({
|
|
252
256
|
file: file,
|
|
253
257
|
sql: sql,
|
|
258
|
+
rowFilter: (row)=>{
|
|
259
|
+
return row["host_key"].match(domainRegexp) != null;
|
|
260
|
+
},
|
|
254
261
|
rowTransform: (row)=>{
|
|
255
262
|
const cookieRow = {
|
|
256
263
|
expiry: (row["expires_utc"] / 1000000 - 11644473600) * 1000,
|
|
@@ -263,7 +270,7 @@ async function $269fe42bfd555305$var$getEncryptedChromeCookie({ name: name , dom
|
|
|
263
270
|
}
|
|
264
271
|
});
|
|
265
272
|
return sqliteQuery1.filter((row)=>{
|
|
266
|
-
return row.domain.match(
|
|
273
|
+
return row.domain.match(domainRegexp) != null;
|
|
267
274
|
});
|
|
268
275
|
}
|
|
269
276
|
async function $269fe42bfd555305$var$getChromePassword() {
|
|
@@ -324,7 +331,7 @@ async function $269fe42bfd555305$var$decrypt(password, encryptedData) {
|
|
|
324
331
|
});
|
|
325
332
|
});
|
|
326
333
|
}
|
|
327
|
-
async function $269fe42bfd555305$export$bd52b72df8d0d261({ file: file , sql: sql , rowTransform: rowTransform }) {
|
|
334
|
+
async function $269fe42bfd555305$export$bd52b72df8d0d261({ file: file , sql: sql , rowFilter: rowFilter = ()=>true , rowTransform: rowTransform }) {
|
|
328
335
|
if (!file || file && !(0, ($parcel$interopDefault($7oI3p$fs))).existsSync(file)) throw new Error(`doSqliteQuery1: file ${file} does not exist`);
|
|
329
336
|
const db = new $7oI3p$sqlite3.Database(file);
|
|
330
337
|
return new Promise((resolve, reject)=>{
|
|
@@ -339,7 +346,7 @@ async function $269fe42bfd555305$export$bd52b72df8d0d261({ file: file , sql: sql
|
|
|
339
346
|
return;
|
|
340
347
|
}
|
|
341
348
|
if (Array.isArray(rows1)) {
|
|
342
|
-
const cookieRows = rows1.map((row)=>{
|
|
349
|
+
const cookieRows = rows1.filter(rowFilter).map((row)=>{
|
|
343
350
|
const newVar = {
|
|
344
351
|
meta: {
|
|
345
352
|
file: file
|
|
@@ -543,7 +550,7 @@ class $e4efb16e005540de$export$2e2bcd8739ae039 {
|
|
|
543
550
|
domain: cookie.domain ?? cookieSpec.domain,
|
|
544
551
|
name: cookie.key ?? cookieSpec.name,
|
|
545
552
|
value: cookie.value,
|
|
546
|
-
expiry: cookie.expires ?? Infinity,
|
|
553
|
+
expiry: cookie.expires ?? "Infinity",
|
|
547
554
|
meta: {
|
|
548
555
|
file: "tough-cookie"
|
|
549
556
|
}
|
|
@@ -688,7 +695,6 @@ async function $f9b70200901ad17d$export$c44c5fdef43f0941(params) {
|
|
|
688
695
|
|
|
689
696
|
|
|
690
697
|
|
|
691
|
-
|
|
692
698
|
function $9c43c2ed82e63570$export$9abc0a414b0d8b8f(results) {
|
|
693
699
|
// sort by name and expiry descending
|
|
694
700
|
// takes the latest expiry for each name
|
|
@@ -704,17 +710,27 @@ function $9c43c2ed82e63570$export$9abc0a414b0d8b8f(results) {
|
|
|
704
710
|
|
|
705
711
|
|
|
706
712
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
713
|
+
|
|
714
|
+
async function $8ef2ebdbd659489d$export$a65902517ae87ba8(cookieSpec) {
|
|
715
|
+
const cookies = [];
|
|
716
|
+
if (Array.isArray(cookieSpec)) {
|
|
717
|
+
const cookieSpecs = cookieSpec;
|
|
718
|
+
for (const cookieSpec1 of cookieSpecs){
|
|
719
|
+
const cookies1 = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(cookieSpec1);
|
|
720
|
+
cookies.push(...cookies1);
|
|
721
|
+
}
|
|
722
|
+
} else {
|
|
723
|
+
const singleQuery = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)(cookieSpec);
|
|
724
|
+
cookies.push(...singleQuery);
|
|
725
|
+
}
|
|
726
|
+
return (0, $7oI3p$lodash.uniqBy)(cookies, JSON.stringify);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
async function $300d8b33187a203c$export$4d2e9997e2c23417(cookieSpec) {
|
|
731
|
+
const cookies = await (0, $8ef2ebdbd659489d$export$a65902517ae87ba8)(cookieSpec);
|
|
712
732
|
if (cookies.length == 0) throw new Error("Cookie not found");
|
|
713
|
-
const
|
|
714
|
-
name: name,
|
|
715
|
-
domain: domain
|
|
716
|
-
});
|
|
717
|
-
const groupedByFile = (0, $7oI3p$lodash.groupBy)(results, (r)=>r.meta?.file);
|
|
733
|
+
const groupedByFile = (0, $7oI3p$lodash.groupBy)(cookies, (r)=>r.meta?.file);
|
|
718
734
|
return Object.keys(groupedByFile).map((file)=>{
|
|
719
735
|
const results = groupedByFile[file];
|
|
720
736
|
return (0, $9c43c2ed82e63570$export$9abc0a414b0d8b8f)(results);
|
|
@@ -724,18 +740,10 @@ async function $300d8b33187a203c$export$4d2e9997e2c23417({ name: name , domain:
|
|
|
724
740
|
|
|
725
741
|
|
|
726
742
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
domain: domain
|
|
732
|
-
}, new (0, $f72befa528c23ca7$export$2e2bcd8739ae039)());
|
|
733
|
-
if (cookies.length == 0) throw new Error("Cookie not found");
|
|
734
|
-
const results = await (0, $7a068a32d4710f0b$export$e6d428437cf2cacb)({
|
|
735
|
-
name: name,
|
|
736
|
-
domain: domain
|
|
737
|
-
});
|
|
738
|
-
return (0, $9c43c2ed82e63570$export$9abc0a414b0d8b8f)(results);
|
|
743
|
+
async function $4ffeaeb7bb3c0319$export$cfc0723de5712e57(cookieSpec) {
|
|
744
|
+
const cookies = await (0, $8ef2ebdbd659489d$export$a65902517ae87ba8)(cookieSpec);
|
|
745
|
+
if (cookies.length > 0) return (0, $9c43c2ed82e63570$export$9abc0a414b0d8b8f)(cookies);
|
|
746
|
+
return "";
|
|
739
747
|
}
|
|
740
748
|
|
|
741
749
|
|
|
@@ -747,31 +755,48 @@ async function $4ffeaeb7bb3c0319$export$cfc0723de5712e57({ name: name , domain:
|
|
|
747
755
|
|
|
748
756
|
|
|
749
757
|
|
|
758
|
+
|
|
759
|
+
function $2d84054eb5f070a6$export$f266452a5050185d(url) {
|
|
760
|
+
const url1 = typeof url == "string" ? new URL(url) : url;
|
|
761
|
+
const cookieSpecs = [];
|
|
762
|
+
const splits = url1.hostname.split(".");
|
|
763
|
+
const tld = splits.slice(-2).join(".");
|
|
764
|
+
const cookieSpec = {
|
|
765
|
+
name: "%",
|
|
766
|
+
domain: "%." + tld
|
|
767
|
+
};
|
|
768
|
+
cookieSpecs.push(cookieSpec);
|
|
769
|
+
const cookieSpec1 = {
|
|
770
|
+
name: "%",
|
|
771
|
+
domain: url1.hostname
|
|
772
|
+
};
|
|
773
|
+
cookieSpecs.push(cookieSpec1);
|
|
774
|
+
// const isWww = splits.slice(-3)[0] === "www";
|
|
775
|
+
const cookieSpec2 = {
|
|
776
|
+
name: "%",
|
|
777
|
+
domain: tld
|
|
778
|
+
};
|
|
779
|
+
cookieSpecs.push(cookieSpec2);
|
|
780
|
+
return (0, $7oI3p$lodash.uniqBy)(cookieSpecs, JSON.stringify);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
|
|
750
784
|
async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetch = (0, $7oI3p$crossfetch.fetch)) {
|
|
785
|
+
const headers = {
|
|
786
|
+
"User-Agent": new (0, ($parcel$interopDefault($7oI3p$useragents)))().toString()
|
|
787
|
+
};
|
|
751
788
|
const defaultOptions = {
|
|
752
|
-
headers:
|
|
753
|
-
"User-Agent": new (0, ($parcel$interopDefault($7oI3p$useragents)))().toString()
|
|
754
|
-
},
|
|
789
|
+
headers: headers,
|
|
755
790
|
redirect: "manual"
|
|
756
791
|
};
|
|
757
792
|
const url2 = `${url}`;
|
|
758
793
|
const url1 = new URL(url2);
|
|
759
|
-
const
|
|
760
|
-
|
|
761
|
-
});
|
|
762
|
-
const cookieSpec = {
|
|
763
|
-
name: "%",
|
|
764
|
-
domain: domain
|
|
765
|
-
};
|
|
766
|
-
// const cookies: string[] = await getGroupedRenderedCookies(cookieSpec).catch(
|
|
767
|
-
// () => []
|
|
768
|
-
// );
|
|
769
|
-
// const cookie = cookies.pop();
|
|
770
|
-
const cookie = await (0, $4ffeaeb7bb3c0319$export$cfc0723de5712e57)(cookieSpec).catch(()=>"");
|
|
771
|
-
const headers = {};
|
|
794
|
+
const cookieSpecs = (0, $2d84054eb5f070a6$export$f266452a5050185d)(url1);
|
|
795
|
+
const cookie = await (0, $4ffeaeb7bb3c0319$export$cfc0723de5712e57)(cookieSpecs).catch(()=>"");
|
|
772
796
|
if (cookie.length > 0) (0, $7oI3p$lodash.merge)(headers, {
|
|
773
797
|
Cookie: cookie
|
|
774
798
|
});
|
|
799
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b)["dump-request-headers"]) console.log((0, $7oI3p$colorette.blue)("Request headers:"), headers);
|
|
775
800
|
const newOptions1 = (0, $7oI3p$lodash.merge)(defaultOptions, options, {
|
|
776
801
|
headers: headers
|
|
777
802
|
});
|
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.11",
|
|
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",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
},
|
|
26
26
|
"targets": {
|
|
27
27
|
"main": {},
|
|
28
|
-
"types": {},
|
|
29
28
|
"library": {
|
|
30
29
|
"source": "src/index.ts",
|
|
31
30
|
"distDir": "dist",
|
|
@@ -33,6 +32,7 @@
|
|
|
33
32
|
"engines": {
|
|
34
33
|
"node": "16"
|
|
35
34
|
},
|
|
35
|
+
"sourceMap": true,
|
|
36
36
|
"includeNodeModules": false
|
|
37
37
|
},
|
|
38
38
|
"cli": {
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": "16"
|
|
44
44
|
},
|
|
45
|
+
"sourceMap": false,
|
|
45
46
|
"includeNodeModules": [
|
|
46
47
|
"colorette"
|
|
47
48
|
]
|
package/src/CookieSpec.ts
CHANGED
package/src/CookieStore.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import CookieQueryStrategy from "./CookieQueryStrategy";
|
|
2
2
|
import { execSimple } from "../utils";
|
|
3
3
|
import { env, HOME } from "../global";
|
|
4
|
-
import { existsSync } from "fs";
|
|
4
|
+
import fs, { existsSync } from "fs";
|
|
5
5
|
import { findAllFiles } from "../findAllFiles";
|
|
6
6
|
import * as crypto from "crypto";
|
|
7
7
|
import * as path from "path";
|
|
8
|
-
import { doSqliteQuery1 } from "../doSqliteQuery1";
|
|
9
8
|
import { merge } from "lodash";
|
|
10
9
|
import { isCookieRow } from "../IsCookieRow";
|
|
11
10
|
import { isExportedCookie } from "../IsExportedCookie";
|
|
@@ -13,7 +12,6 @@ import CookieRow from "../CookieRow";
|
|
|
13
12
|
import ExportedCookie from "../ExportedCookie";
|
|
14
13
|
import { stringToRegex } from "../StringToRegex";
|
|
15
14
|
import { parsedArgs } from "../argv";
|
|
16
|
-
import fs from "fs";
|
|
17
15
|
import * as sqlite3 from "sqlite3";
|
|
18
16
|
import { DoSqliteQuery1Params } from "../doSqliteQuery1Params";
|
|
19
17
|
|
|
@@ -113,11 +111,15 @@ Promise<ExportedCookie[]> {
|
|
|
113
111
|
meta: meta,
|
|
114
112
|
};
|
|
115
113
|
const expiry = cookieRow.expiry;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
const mergeExpiry =
|
|
115
|
+
expiry != null && expiry > 0
|
|
116
|
+
? {
|
|
117
|
+
expiry: new Date(expiry),
|
|
118
|
+
}
|
|
119
|
+
: {
|
|
120
|
+
expiry: "Infinity",
|
|
121
|
+
};
|
|
122
|
+
merge(exportedCookie, mergeExpiry);
|
|
121
123
|
return exportedCookie;
|
|
122
124
|
});
|
|
123
125
|
const results: ExportedCookie[] = (await Promise.all(decrypted)).filter(
|
|
@@ -179,9 +181,16 @@ async function getEncryptedChromeCookie({
|
|
|
179
181
|
sql += `host_key LIKE '${sqlEmbedDomain}';`;
|
|
180
182
|
}
|
|
181
183
|
}
|
|
184
|
+
if (parsedArgs.verbose) {
|
|
185
|
+
console.log("sql", sql);
|
|
186
|
+
}
|
|
187
|
+
const domainRegexp: RegExp = stringToRegex(domain);
|
|
182
188
|
const sqliteQuery1: CookieRow[] = await doChromeSqliteQuery1({
|
|
183
189
|
file: file,
|
|
184
190
|
sql: sql,
|
|
191
|
+
rowFilter: (row) => {
|
|
192
|
+
return row["host_key"].match(domainRegexp) != null;
|
|
193
|
+
},
|
|
185
194
|
rowTransform: (row) => {
|
|
186
195
|
const cookieRow = {
|
|
187
196
|
expiry: (row["expires_utc"] / 1000000 - 11644473600) * 1000,
|
|
@@ -196,7 +205,7 @@ async function getEncryptedChromeCookie({
|
|
|
196
205
|
},
|
|
197
206
|
});
|
|
198
207
|
return sqliteQuery1.filter((row) => {
|
|
199
|
-
return row.domain.match(
|
|
208
|
+
return row.domain.match(domainRegexp) != null;
|
|
200
209
|
});
|
|
201
210
|
}
|
|
202
211
|
|
|
@@ -304,6 +313,7 @@ async function decrypt(
|
|
|
304
313
|
export async function doChromeSqliteQuery1({
|
|
305
314
|
file,
|
|
306
315
|
sql,
|
|
316
|
+
rowFilter = () => true,
|
|
307
317
|
rowTransform,
|
|
308
318
|
}: DoSqliteQuery1Params): Promise<CookieRow[]> {
|
|
309
319
|
if (!file || (file && !fs.existsSync(file))) {
|
|
@@ -322,15 +332,17 @@ export async function doChromeSqliteQuery1({
|
|
|
322
332
|
return;
|
|
323
333
|
}
|
|
324
334
|
if (Array.isArray(rows1)) {
|
|
325
|
-
const cookieRows: CookieRow[] = rows1
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
335
|
+
const cookieRows: CookieRow[] = rows1
|
|
336
|
+
.filter(rowFilter)
|
|
337
|
+
.map((row: any) => {
|
|
338
|
+
const newVar = {
|
|
339
|
+
meta: {
|
|
340
|
+
file: file,
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
const cookieRow: CookieRow = rowTransform(row);
|
|
344
|
+
return merge(newVar, cookieRow);
|
|
345
|
+
});
|
|
334
346
|
resolve(cookieRows);
|
|
335
347
|
return;
|
|
336
348
|
}
|
|
@@ -2,7 +2,7 @@ import CookieQueryStrategy from "./CookieQueryStrategy";
|
|
|
2
2
|
import CookieSpec from "../CookieSpec";
|
|
3
3
|
import ExportedCookie from "../ExportedCookie";
|
|
4
4
|
import { Cookie } from "tough-cookie";
|
|
5
|
-
import {
|
|
5
|
+
import { cookieJar, cookieStore } from "../CookieStore";
|
|
6
6
|
import { stringToRegex } from "../StringToRegex";
|
|
7
7
|
|
|
8
8
|
export default class CookieStoreQueryStrategy implements CookieQueryStrategy {
|
|
@@ -59,7 +59,7 @@ export default class CookieStoreQueryStrategy implements CookieQueryStrategy {
|
|
|
59
59
|
domain: cookie.domain ?? cookieSpec.domain,
|
|
60
60
|
name: cookie.key ?? cookieSpec.name,
|
|
61
61
|
value: cookie.value,
|
|
62
|
-
expiry: cookie.expires ?? Infinity,
|
|
62
|
+
expiry: cookie.expires ?? "Infinity",
|
|
63
63
|
meta: {
|
|
64
64
|
file: "tough-cookie",
|
|
65
65
|
},
|
package/src/cli.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { argv, parsedArgs } from "./argv";
|
|
4
|
-
import { queryCookies } from "./queryCookies";
|
|
5
4
|
import { groupBy } from "lodash";
|
|
6
5
|
import { green, red, yellow } from "colorette";
|
|
7
6
|
import { resultsRendered } from "./resultsRendered";
|
|
8
7
|
import { fetchWithCookies } from "./fetchWithCookies";
|
|
9
8
|
import { unpackHeaders } from "./unpackHeaders";
|
|
10
9
|
import CookieSpec from "./CookieSpec";
|
|
10
|
+
import { comboQueryCookieSpec } from "./comboQueryCookieSpec";
|
|
11
|
+
import { cookieSpecsFromUrl } from "./cookieSpecsFromUrl";
|
|
11
12
|
|
|
12
|
-
async function cliQueryCookies(
|
|
13
|
+
async function cliQueryCookies(cookieSpec: CookieSpec | CookieSpec[]) {
|
|
13
14
|
try {
|
|
14
|
-
const results = await
|
|
15
|
+
const results = await comboQueryCookieSpec(cookieSpec);
|
|
15
16
|
if (results == null || results.length == 0) {
|
|
16
17
|
console.error(red("No results"));
|
|
17
18
|
return;
|
|
@@ -49,7 +50,7 @@ async function cliQueryCookies({ name, domain }: CookieSpec) {
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
function main() {
|
|
53
|
+
async function main() {
|
|
53
54
|
if (parsedArgs["help"] || parsedArgs["h"]) {
|
|
54
55
|
console.log(`Usage: ${argv[1]} [name] [domain] [options] `);
|
|
55
56
|
console.log(`Options:`);
|
|
@@ -61,6 +62,8 @@ function main() {
|
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
parsedArgs["verbose"] = parsedArgs["verbose"] || parsedArgs["v"];
|
|
66
|
+
|
|
64
67
|
const fetchUrl: string = parsedArgs["fetch"] || parsedArgs["F"];
|
|
65
68
|
if (fetchUrl) {
|
|
66
69
|
let url: URL;
|
|
@@ -100,12 +103,24 @@ function main() {
|
|
|
100
103
|
return;
|
|
101
104
|
}
|
|
102
105
|
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
const cookieSpecs: CookieSpec[] = [];
|
|
107
|
+
const argUrl: string = parsedArgs["url"] || parsedArgs["u"];
|
|
108
|
+
if (argUrl) {
|
|
109
|
+
for (const cookieSpec of cookieSpecsFromUrl(argUrl)) {
|
|
110
|
+
cookieSpecs.push(cookieSpec);
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
cookieSpecs.push({
|
|
114
|
+
name: parsedArgs["name"] || parsedArgs["_"][0] || "%",
|
|
115
|
+
domain: parsedArgs["domain"] || parsedArgs["_"][1] || "%",
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (parsedArgs.verbose) {
|
|
120
|
+
console.log("cookieSpecs", cookieSpecs);
|
|
121
|
+
}
|
|
107
122
|
|
|
108
|
-
cliQueryCookies(
|
|
123
|
+
await cliQueryCookies(cookieSpecs).catch(console.error);
|
|
109
124
|
}
|
|
110
125
|
|
|
111
|
-
main();
|
|
126
|
+
main().then((r) => r, console.error);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import CookieSpec, { MultiCookieSpec } from "./CookieSpec";
|
|
2
|
+
import ExportedCookie from "./ExportedCookie";
|
|
3
|
+
import { queryCookies } from "./queryCookies";
|
|
4
|
+
import { uniqBy } from "lodash";
|
|
5
|
+
|
|
6
|
+
export async function comboQueryCookieSpec(
|
|
7
|
+
cookieSpec: MultiCookieSpec
|
|
8
|
+
): Promise<ExportedCookie[]> {
|
|
9
|
+
const cookies: ExportedCookie[] = [];
|
|
10
|
+
if (Array.isArray(cookieSpec)) {
|
|
11
|
+
const cookieSpecs = <CookieSpec[]>cookieSpec;
|
|
12
|
+
for (const cookieSpec1 of cookieSpecs) {
|
|
13
|
+
const cookies1: ExportedCookie[] = await queryCookies(cookieSpec1);
|
|
14
|
+
cookies.push(...cookies1);
|
|
15
|
+
}
|
|
16
|
+
} else {
|
|
17
|
+
const singleQuery = await queryCookies(cookieSpec);
|
|
18
|
+
cookies.push(...singleQuery);
|
|
19
|
+
}
|
|
20
|
+
return uniqBy(cookies, JSON.stringify);
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import CookieSpec from "./CookieSpec";
|
|
2
|
+
import { uniqBy } from "lodash";
|
|
3
|
+
|
|
4
|
+
export function cookieSpecsFromUrl(url: URL | string): CookieSpec[] {
|
|
5
|
+
const url1 = typeof url == "string" ? new URL(url) : url;
|
|
6
|
+
const cookieSpecs = [];
|
|
7
|
+
const splits = url1.hostname.split(".");
|
|
8
|
+
const tld = splits.slice(-2).join(".");
|
|
9
|
+
const cookieSpec: CookieSpec = {
|
|
10
|
+
name: "%",
|
|
11
|
+
domain: "%." + tld,
|
|
12
|
+
};
|
|
13
|
+
cookieSpecs.push(cookieSpec);
|
|
14
|
+
const cookieSpec1: CookieSpec = {
|
|
15
|
+
name: "%",
|
|
16
|
+
domain: url1.hostname,
|
|
17
|
+
};
|
|
18
|
+
cookieSpecs.push(cookieSpec1);
|
|
19
|
+
// const isWww = splits.slice(-3)[0] === "www";
|
|
20
|
+
const cookieSpec2: CookieSpec = {
|
|
21
|
+
name: "%",
|
|
22
|
+
domain: tld,
|
|
23
|
+
};
|
|
24
|
+
cookieSpecs.push(cookieSpec2);
|
|
25
|
+
return uniqBy(cookieSpecs, JSON.stringify);
|
|
26
|
+
}
|
package/src/fetchWithCookies.ts
CHANGED
|
@@ -4,44 +4,38 @@ import { fetch as fetchImpl } from "cross-fetch";
|
|
|
4
4
|
import { merge } from "lodash";
|
|
5
5
|
// noinspection SpellCheckingInspection
|
|
6
6
|
import destr from "destr";
|
|
7
|
-
import CookieSpec from "./CookieSpec";
|
|
8
7
|
import { cookieJar } from "./CookieStore";
|
|
9
8
|
import UserAgent from "user-agents";
|
|
10
9
|
import { parsedArgs } from "./argv";
|
|
11
10
|
import { blue, yellow } from "colorette";
|
|
12
11
|
import { getMergedRenderedCookies } from "./getMergedRenderedCookies";
|
|
12
|
+
import { cookieSpecsFromUrl } from "./cookieSpecsFromUrl";
|
|
13
|
+
import CookieSpec from "./CookieSpec";
|
|
13
14
|
|
|
14
15
|
export async function fetchWithCookies(
|
|
15
16
|
url: RequestInfo | URL,
|
|
16
17
|
options: RequestInit | undefined = {},
|
|
17
18
|
fetch: Function = fetchImpl
|
|
18
19
|
): Promise<Response> {
|
|
20
|
+
const headers = {
|
|
21
|
+
"User-Agent": new UserAgent().toString(),
|
|
22
|
+
};
|
|
19
23
|
const defaultOptions: RequestInit = {
|
|
20
|
-
headers
|
|
21
|
-
"User-Agent": new UserAgent().toString(),
|
|
22
|
-
},
|
|
24
|
+
headers,
|
|
23
25
|
redirect: "manual",
|
|
24
26
|
};
|
|
25
27
|
const url2: string = `${url}`;
|
|
26
28
|
const url1: URL = new URL(url2);
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
const cookieSpec: CookieSpec = {
|
|
31
|
-
name: "%",
|
|
32
|
-
domain: domain,
|
|
33
|
-
};
|
|
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 = {};
|
|
29
|
+
const cookieSpecs: CookieSpec[] = cookieSpecsFromUrl(url1);
|
|
30
|
+
const cookie = await getMergedRenderedCookies(cookieSpecs).catch(() => "");
|
|
40
31
|
if (cookie.length > 0) {
|
|
41
32
|
merge(headers, {
|
|
42
33
|
Cookie: cookie,
|
|
43
34
|
});
|
|
44
35
|
}
|
|
36
|
+
if (parsedArgs["dump-request-headers"]) {
|
|
37
|
+
console.log(blue("Request headers:"), headers);
|
|
38
|
+
}
|
|
45
39
|
const newOptions1: RequestInit = merge(defaultOptions, options, { headers });
|
|
46
40
|
try {
|
|
47
41
|
const res: Response = await fetch(url2, newOptions1);
|
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
import { groupBy } from "lodash";
|
|
2
|
-
import { queryCookies } from "./queryCookies";
|
|
3
2
|
import { resultsRendered } from "./resultsRendered";
|
|
4
|
-
import
|
|
5
|
-
import CookieSpec from "./CookieSpec";
|
|
3
|
+
import { MultiCookieSpec } from "./CookieSpec";
|
|
6
4
|
import ExportedCookie from "./ExportedCookie";
|
|
5
|
+
import { comboQueryCookieSpec } from "./comboQueryCookieSpec";
|
|
7
6
|
|
|
8
|
-
export async function getGroupedRenderedCookies(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const cookies: ExportedCookie[] = await queryCookies(
|
|
13
|
-
{
|
|
14
|
-
name,
|
|
15
|
-
domain,
|
|
16
|
-
},
|
|
17
|
-
new CompositeCookieQueryStrategy()
|
|
18
|
-
//
|
|
19
|
-
);
|
|
7
|
+
export async function getGroupedRenderedCookies(
|
|
8
|
+
cookieSpec: MultiCookieSpec
|
|
9
|
+
): Promise<string[]> {
|
|
10
|
+
const cookies: ExportedCookie[] = await comboQueryCookieSpec(cookieSpec);
|
|
20
11
|
if (cookies.length == 0) {
|
|
21
12
|
throw new Error("Cookie not found");
|
|
22
13
|
}
|
|
23
|
-
const
|
|
24
|
-
const groupedByFile = groupBy(results, (r: ExportedCookie) => r.meta?.file);
|
|
14
|
+
const groupedByFile = groupBy(cookies, (r: ExportedCookie) => r.meta?.file);
|
|
25
15
|
return Object.keys(groupedByFile).map((file: string) => {
|
|
26
16
|
const results: ExportedCookie[] = groupedByFile[file];
|
|
27
17
|
return resultsRendered(results);
|
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
import { groupBy } from "lodash";
|
|
2
|
-
import { queryCookies } from "./queryCookies";
|
|
3
1
|
import { resultsRendered } from "./resultsRendered";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import { comboQueryCookieSpec } from "./comboQueryCookieSpec";
|
|
3
|
+
import { MultiCookieSpec } from "./CookieSpec";
|
|
6
4
|
import ExportedCookie from "./ExportedCookie";
|
|
7
5
|
|
|
8
|
-
export async function getMergedRenderedCookies(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
name,
|
|
15
|
-
domain,
|
|
16
|
-
},
|
|
17
|
-
new CompositeCookieQueryStrategy()
|
|
18
|
-
//
|
|
19
|
-
);
|
|
20
|
-
if (cookies.length == 0) {
|
|
21
|
-
throw new Error("Cookie not found");
|
|
6
|
+
export async function getMergedRenderedCookies(
|
|
7
|
+
cookieSpec: MultiCookieSpec
|
|
8
|
+
): Promise<string> {
|
|
9
|
+
const cookies: ExportedCookie[] = await comboQueryCookieSpec(cookieSpec);
|
|
10
|
+
if (cookies.length > 0) {
|
|
11
|
+
return resultsRendered(cookies);
|
|
22
12
|
}
|
|
23
|
-
|
|
24
|
-
return resultsRendered(results);
|
|
13
|
+
return "";
|
|
25
14
|
}
|