@mherod/get-cookie 2.0.0-rc.9 → 2.1.1

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 (77) hide show
  1. package/.idea/runConfigurations/build.xml +12 -0
  2. package/.parcelrc +12 -0
  3. package/.prettierignore +5 -0
  4. package/.prettierrc +12 -0
  5. package/.terserrc +26 -0
  6. package/README.md +2 -2
  7. package/build-indexes.ts +108 -0
  8. package/dist/cli.js +2 -0
  9. package/dist/index.js +1235 -621
  10. package/dist/index.js.map +1 -0
  11. package/dist/module.js +1446 -0
  12. package/dist/module.js.map +1 -0
  13. package/dist/prompt.2b8c61c0.js +40 -0
  14. package/dist/prompt.536a2c51.js +40 -0
  15. package/dist/prompt.fb2c7dad.js.map +1 -0
  16. package/dist/types.d.ts +30 -0
  17. package/dist/types.d.ts.map +1 -0
  18. package/jest.config.ts +14 -0
  19. package/package-lock.json +3862 -8098
  20. package/package.json +46 -34
  21. package/src/CookieRow.ts +8 -0
  22. package/src/CookieSpec.ts +20 -0
  23. package/src/CookieStore.ts +24 -7
  24. package/src/ExportedCookie.ts +12 -0
  25. package/src/FetchResponse.ts +1 -3
  26. package/src/FileCookieStore.ts +178 -0
  27. package/src/StringToRegex.ts +10 -0
  28. package/src/argv.ts +27 -2
  29. package/src/browsers/CompositeCookieQueryStrategy.ts +36 -38
  30. package/src/browsers/CookieQueryStrategy.ts +1 -0
  31. package/src/browsers/CookieStoreQueryStrategy.ts +29 -22
  32. package/src/browsers/QuerySqliteThenTransform.ts +85 -0
  33. package/src/browsers/chrome/ChromeApplicationSupport.ts +10 -0
  34. package/src/browsers/chrome/ChromeCookieQueryStrategy.ts +131 -0
  35. package/src/browsers/chrome/decrypt.ts +118 -0
  36. package/src/browsers/chrome/getChromePassword.ts +11 -0
  37. package/src/browsers/{FirefoxCookieQueryStrategy.ts → firefox/FirefoxCookieQueryStrategy.ts} +19 -16
  38. package/src/browsers/getEncryptedChromeCookie.ts +87 -0
  39. package/src/browsers/index.ts +12 -0
  40. package/src/browsers/mock/MockCookieQueryStrategy.ts +18 -0
  41. package/src/browsers/{SafariCookieQueryStrategy.ts → safari/SafariCookieQueryStrategy.ts} +3 -2
  42. package/src/cli.ts +43 -67
  43. package/src/cliQueryCookies.ts +55 -0
  44. package/src/comboQueryCookieSpec.test.ts +92 -0
  45. package/src/comboQueryCookieSpec.ts +29 -0
  46. package/src/cookieQueryOptions.ts +20 -0
  47. package/src/cookieSpecsFromUrl.test.ts +65 -0
  48. package/src/cookieSpecsFromUrl.ts +27 -0
  49. package/src/execSimple.ts +13 -0
  50. package/src/fetchWithCookies.test.ts +32 -0
  51. package/src/fetchWithCookies.ts +123 -49
  52. package/src/findAllFiles.ts +25 -49
  53. package/src/getChromeCookie.ts +6 -4
  54. package/src/getCookie.ts +6 -3
  55. package/src/getFirefoxCookie.ts +6 -4
  56. package/src/getGroupedRenderedCookies.ts +7 -17
  57. package/src/getMergedRenderedCookies.test.ts +43 -0
  58. package/src/getMergedRenderedCookies.ts +13 -21
  59. package/src/global.ts +1 -1
  60. package/src/index.ts +0 -7
  61. package/src/isValidJwt.ts +2 -2
  62. package/src/listChromeProfiles.ts +45 -0
  63. package/src/logger.ts +13 -0
  64. package/src/processBeforeReturn.ts +26 -0
  65. package/src/queryCookies.ts +11 -3
  66. package/src/util/flatMapAsync.test.ts +55 -0
  67. package/src/util/flatMapAsync.ts +37 -0
  68. package/src/util/index.ts +1 -0
  69. package/tsconfig.json +14 -11
  70. package/.github/dependabot.yml +0 -6
  71. package/.prettierrc.json +0 -1
  72. package/src/IsCookieRow.ts +0 -9
  73. package/src/IsExportedCookie.ts +0 -9
  74. package/src/browsers/ChromeCookieQueryStrategy.ts +0 -343
  75. package/src/doSqliteQuery1.ts +0 -47
  76. package/src/doSqliteQuery1Params.ts +0 -7
  77. package/src/utils.ts +0 -25
@@ -0,0 +1,12 @@
1
+ <component name="ProjectRunConfigurationManager">
2
+ <configuration default="false" name="build" type="js.build_tools.npm" nameIsGenerated="true">
3
+ <package-json value="$PROJECT_DIR$/package.json" />
4
+ <command value="run" />
5
+ <scripts>
6
+ <script value="build" />
7
+ </scripts>
8
+ <node-interpreter value="project" />
9
+ <envs />
10
+ <method v="2" />
11
+ </configuration>
12
+ </component>
package/.parcelrc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "@parcel/config-default",
3
+ "transformers": {
4
+ "*.{ts,tsx}": [
5
+ "@parcel/transformer-typescript-tsc",
6
+ "..."
7
+ ],
8
+ "*": [
9
+ "..."
10
+ ]
11
+ }
12
+ }
@@ -0,0 +1,5 @@
1
+ .idea/**/workspace.xml
2
+ *.log
3
+ node_modules/
4
+ .parcel-cache
5
+ dist
package/.prettierrc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "useTabs": false,
3
+ "overrides": [
4
+ {
5
+ "files": [".prettierrc", ".parcelrc"],
6
+ "options": {
7
+ "parser": "json",
8
+ "tabWidth": 2
9
+ }
10
+ }
11
+ ]
12
+ }
package/.terserrc ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "toplevel": true,
3
+ "keep_fnames": true,
4
+ "keep_classnames": true,
5
+ "parse": {
6
+ "bare_returns": true,
7
+ "html5_comments": true,
8
+ "shebang": true,
9
+ },
10
+ "compress": {
11
+ "drop_console": false,
12
+ "toplevel": true,
13
+ "evaluate": true,
14
+ "passes": 3,
15
+ "keep_fnames": true,
16
+ "keep_classnames": true,
17
+ "hoist_funs": true,
18
+ },
19
+ "mangle": {
20
+ "toplevel": true,
21
+ },
22
+ "format": {
23
+ "comments": false,
24
+ "beautify": false,
25
+ }
26
+ }
package/README.md CHANGED
@@ -28,6 +28,6 @@ The output of the command will be the value of the cookie.
28
28
  The library can also be used as a module.
29
29
 
30
30
  ```javascript
31
- const {getCookie} = require('@mherod/get-cookie');
32
- getCookie('auth', 'www.example.com').then(console.log);
31
+ const { getCookie } = require("@mherod/get-cookie");
32
+ getCookie("auth", "www.example.com").then(console.log);
33
33
  ```
@@ -0,0 +1,108 @@
1
+ //#!/usr/bin/env bun run
2
+
3
+ import consola from "consola";
4
+ import { groupBy, orderBy } from "lodash";
5
+ import path from "path";
6
+ import { existsSync, readFileSync, writeFileSync } from "fs";
7
+ import { sync } from "fast-glob";
8
+ import prettier from "prettier";
9
+
10
+ async function main() {
11
+ // find all ts files in src and build indexes
12
+
13
+ const files = sync("src/**/*.ts", {
14
+ dot: true,
15
+ onlyFiles: true,
16
+ ignore: [
17
+ "**/index.ts",
18
+ "**/*.d.ts",
19
+ "**/*.test.{ts,tsx}",
20
+ "**/*.spec.{ts,tsx}",
21
+ "**/*.stories.tsx",
22
+ ],
23
+ //
24
+ });
25
+
26
+ // group files by directory
27
+ const groups = groupBy(files, (file: string) => {
28
+ const parts = file.split("/");
29
+ parts.pop();
30
+ return parts.join("/");
31
+ });
32
+ // order by depth, so that we build indexes for subdirectories first
33
+ const dirs = orderBy(
34
+ Object.keys(groups),
35
+ (dir) => dir.split("/").length,
36
+ //
37
+ );
38
+
39
+ // build index for each directory
40
+ for (const dir of dirs) {
41
+ consola.info(`building index for ${dir}`);
42
+ const files = groups[dir].filter((file: string) => file.match(/\.ts$/));
43
+ const indexes = files
44
+ .map((file: string) => {
45
+ const content = readFileSync(file, "utf-8").split("\n");
46
+ if (!content.some((line) => line.trim().startsWith("export"))) {
47
+ // if none of the lines in the file start with an export, then we should not include it in the index
48
+ return "";
49
+ }
50
+ const name = path
51
+ .relative(dir, file) //
52
+ .replace(/\.ts$/, ""); //
53
+ return `export * from './${name}';`;
54
+ })
55
+ .filter(Boolean)
56
+ .sort() as string[];
57
+
58
+ // then find subdirectories and build index for them
59
+
60
+ const subIndex = sync(`${dir}/*/index.ts`, {
61
+ dot: true,
62
+ onlyFiles: true,
63
+ //
64
+ });
65
+
66
+ if (subIndex.length > 0) {
67
+ indexes.push(
68
+ ...subIndex.map((file: string) => {
69
+ const name = path
70
+ .relative(dir, file) //
71
+ .replace(/\/index\.ts$/, ""); //
72
+ return `export * from './${name}';`;
73
+ }),
74
+ );
75
+ }
76
+
77
+ const index = indexes.join("\n");
78
+
79
+ // const indexFile = `${dir}/index.ts`
80
+ const indexFile = path.join(dir, "index.ts");
81
+
82
+ const output = await prettier.format(index, { parser: "babel" });
83
+
84
+ if (existsSync(indexFile)) {
85
+ const existingContent = readFileSync(indexFile, "utf8");
86
+ if (existingContent === output) {
87
+ continue;
88
+ }
89
+ const lines = existingContent.split("\n");
90
+ if (lines.every((line) => line.startsWith("export * from")) == false) {
91
+ // if the existing index file is not an export index, then we should not overwrite it
92
+ continue;
93
+ }
94
+ }
95
+
96
+ if (output.length > 0) {
97
+ console.log(`writing ${dir}/index.ts`, output.length);
98
+
99
+ writeFileSync(
100
+ indexFile,
101
+ output,
102
+ //
103
+ );
104
+ }
105
+ }
106
+ }
107
+
108
+ main().catch(consola.error);