fetchfox-sdk 1.0.16 → 1.0.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fetchfox-sdk",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "AI scraper",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "git+https://github.com/fetchfox/fetchfox.git"
14
+ "url": "git+https://github.com/fetchfox/fetchfox-sdk.git"
15
15
  },
16
16
  "keywords": [
17
17
  "ai",
@@ -20,9 +20,9 @@
20
20
  "author": "marcell@fetchfoxai.com",
21
21
  "license": "ISC",
22
22
  "bugs": {
23
- "url": "https://github.com/fetchfox/fetchfox/issues"
23
+ "url": "https://github.com/fetchfox/fetchfox-sdk/issues"
24
24
  },
25
- "homepage": "https://github.com/fetchfox/fetchfox#readme",
25
+ "homepage": "https://fetchfox.ai",
26
26
  "devDependencies": {
27
27
  "@eslint/js": "^9.31.0",
28
28
  "eslint-plugin-promise": "^7.2.1",
package/src/api.js CHANGED
@@ -8,7 +8,7 @@ const camelCase = (obj) => {
8
8
  );
9
9
  };
10
10
 
11
- const endpoint = (path) => `${host()}${path}`;
11
+ const endpoint = (path, params) => `${host(params)}${path}`;
12
12
 
13
13
  const FetchFoxAPIError = class extends Error {
14
14
  constructor(errors) {
@@ -28,7 +28,7 @@ export const call = async (method, path, params) => {
28
28
  },
29
29
  };
30
30
 
31
- let url = endpoint(path);
31
+ let url = endpoint(path, params);
32
32
  if (method == 'GET') {
33
33
  url += '?' + new URLSearchParams(params).toString();
34
34
  } else {
package/src/crawl.js CHANGED
@@ -7,5 +7,5 @@ export async function crawl(args) {
7
7
 
8
8
  crawl.detach = async (args) => {
9
9
  const data = await call('POST', '/api/crawl', { ...args, detach: true });
10
- return new Job(data.jobId);
10
+ return new Job(data.jobId, args);
11
11
  };
package/src/detach.js CHANGED
@@ -12,7 +12,7 @@ export const Job = class {
12
12
  #callbacks;
13
13
  #socket;
14
14
 
15
- constructor(id) {
15
+ constructor(id, options) {
16
16
  this.id = id;
17
17
  this.#callbacks = {
18
18
  completed: [],
@@ -21,7 +21,7 @@ export const Job = class {
21
21
  progress: [],
22
22
  };
23
23
 
24
- this.#socket = new io(ws());
24
+ this.#socket = new io(ws(options));
25
25
  this.#socket.on('progress', (data) => {
26
26
  this.handleProgress(data);
27
27
  });
package/src/extract.js CHANGED
@@ -7,5 +7,5 @@ export async function extract(args) {
7
7
 
8
8
  extract.detach = async (args) => {
9
9
  const data = await call('POST', '/api/extract', { ...args, detach: true });
10
- return new Job(data.jobId);
10
+ return new Job(data.jobId, args);
11
11
  };
package/src/scrape.js CHANGED
@@ -7,5 +7,5 @@ export async function scrape(args) {
7
7
 
8
8
  scrape.detach = async (args) => {
9
9
  const data = await call('POST', '/api/scrape', { ...args, detach: true });
10
- return new Job(data.jobId);
10
+ return new Job(data.jobId, args);
11
11
  };
@@ -32,6 +32,25 @@ test('use fetchfox object for detach @fetchfox @sanity', async () => {
32
32
  expect(count).toBeGreaterThan(0);
33
33
  }, 30_000);
34
34
 
35
+ test('use fetchfox object for extract detach @fetchfox @sanity', async () => {
36
+ const fox = new FetchFox({
37
+ apiKey: process.env.FETCHFOX_API_KEY,
38
+ });
39
+ const job = await fox.extract.detach({
40
+ urls: ['https://pokemondb.net/pokedex/bulbasaur'],
41
+ template: 'name and number',
42
+ });
43
+
44
+ let count = 0;
45
+ job.on('progress', (data) => {
46
+ count++;
47
+ });
48
+
49
+ await job.finished();
50
+
51
+ expect(count).toBeGreaterThan(0);
52
+ }, 30_000);
53
+
35
54
  test('invalid key fails @fetchfox @sanity', async () => {
36
55
  const fox = new FetchFox({
37
56
  apiKey: 'invalid',