@ghostery/trackerdb 1.0.561 → 1.0.562

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 (2) hide show
  1. package/cli.js +39 -5
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -9,23 +9,57 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
9
9
 
10
10
  const debug = process.env.DEBUG === 'true' ? console.log : () => {};
11
11
 
12
- (async () => {
13
- const startTime = Date.now();
14
- const [, , url] = process.argv;
12
+ function showUsage() {
13
+ console.log(`
14
+ Usage: node script.js [--source-url FIRST_PARTY_URL] URL
15
+
16
+ Options:
17
+ --source-url URL Overwrites the source URL (needed to test third-party requests).
18
+ --help Show help.
19
+ `);
20
+ }
21
+
22
+ function parseArguments() {
23
+ const args = process.argv.slice(2);
24
+ if (args.includes('--help')) {
25
+ showUsage();
26
+ process.exit(0);
27
+ }
28
+
29
+ let sourceUrl = null;
30
+ const sourceUrlIndex = args.indexOf('--source-url');
31
+ if (sourceUrlIndex !== -1 && sourceUrlIndex + 1 < args.length) {
32
+ sourceUrl = args[sourceUrlIndex + 1];
33
+ args.splice(sourceUrlIndex, 2);
34
+ }
15
35
 
36
+ const url = args[0];
16
37
  if (!url) {
17
- console.error('trackerdb takes URL as first argument');
38
+ showUsage();
39
+ console.error('ERROR: Missing argument: URL is needed');
18
40
  process.exit(1);
19
41
  }
20
42
 
43
+ return { url, sourceUrl };
44
+ }
45
+
46
+ (async () => {
47
+ const startTime = Date.now();
48
+ const { url, sourceUrl } = parseArguments();
49
+
21
50
  const loadingStart = Date.now();
22
51
  const engine = FiltersEngine.deserialize(
23
52
  readFileSync(path.join(__dirname, 'dist', 'trackerdb.engine')),
24
53
  );
25
54
  const loadingEnd = Date.now();
26
55
 
56
+ const requestDetails = { url: url, type: 'xhr' };
57
+ if (sourceUrl) {
58
+ requestDetails.sourceUrl = sourceUrl;
59
+ }
60
+
27
61
  const matches = url.startsWith('http')
28
- ? engine.getPatternMetadata(Request.fromRawDetails({ url, type: 'xhr' }), {
62
+ ? engine.getPatternMetadata(Request.fromRawDetails(requestDetails), {
29
63
  getDomainMetadata: true,
30
64
  })
31
65
  : engine.metadata.fromDomain(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghostery/trackerdb",
3
- "version": "1.0.561",
3
+ "version": "1.0.562",
4
4
  "description": "Ghostery Tracker Database",
5
5
  "type": "module",
6
6
  "scripts": {