fetchfox-sdk 1.0.13 → 1.0.14

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.13",
3
+ "version": "1.0.14",
4
4
  "description": "AI scraper",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/#index.js# ADDED
@@ -0,0 +1,13 @@
1
+ export * from './scrape.js';
2
+ export * from './crawl.js';
3
+ export * from './extract.js';
4
+ export * from './jobs.js';
5
+ export * from './user.js';
6
+ export * from './credits.js';
7
+ export * from './proxy.js';
8
+ export * from './urls.js';
9
+
10
+ export { Job } from './detach.js';
11
+ export { call } from './api.js';
12
+ export { FetchFox } from './fetchfox.js';
13
+ export { configure, host, ws, apiKey } from './configure.js';
package/src/detach.js CHANGED
@@ -85,6 +85,8 @@ export const Job = class {
85
85
 
86
86
  if (['completed', 'error'].includes(this.state)) {
87
87
  this.trigger('finished');
88
+ // Just in case there are some straggler events, wait a few seconds
89
+ setTimeout(() => socket.disconnect(), 5000);
88
90
  }
89
91
  }
90
92
  }
@@ -0,0 +1,27 @@
1
+ import { crawl } from './crawl.js';
2
+ import { extract } from './extract.js';
3
+ import { scrape } from './scrape.js';
4
+
5
+ export const FetchFox = class {
6
+ constructor({ apiKey, host } = {}) {
7
+ this.apiKey = apiKey;
8
+ this.host = host;
9
+
10
+ const fns = [crawl, extract, scrape];
11
+
12
+ for (const fn of fns) {
13
+ this[fn.name] = (args) =>
14
+ fn({
15
+ apiKey: this.apiKey,
16
+ host: this.host,
17
+ ...args,
18
+ });
19
+ this[fn.name].detach = (args) =>
20
+ fn.detach({
21
+ apiKey: this.apiKey,
22
+ host: this.host,
23
+ ...args,
24
+ });
25
+ }
26
+ }
27
+ };
@@ -0,0 +1,6 @@
1
+ export const FetchFox = class {
2
+ constructor({ apiKey, host } = {}) {
3
+ this.apiKey = apiKey;
4
+ this.host = host;
5
+ }
6
+ }
package/src/index.js CHANGED
@@ -8,4 +8,5 @@ export * from './proxy.js';
8
8
  export * from './urls.js';
9
9
  export { Job } from './detach.js';
10
10
  export { call } from './api.js';
11
+ export { FetchFox } from './fetchfox.js';
11
12
  export { configure, host, ws, apiKey } from './configure.js';
@@ -0,0 +1,32 @@
1
+ import console from 'console';
2
+ global.console = console;
3
+ import { FetchFox } from '../src';
4
+
5
+ test('use fetchfox object @fetchfox @sanity', async () => {
6
+ const fox = new FetchFox({
7
+ apiKey: process.env.FETCHFOX_API_KEY,
8
+ });
9
+ const out = await fox.crawl({
10
+ pattern: 'https://pokemondb.net/pokedex/*',
11
+ maxVisits: 5,
12
+ });
13
+ expect(out.results.hits.length).toBeGreaterThan(10);
14
+ }, 30_000);
15
+
16
+ test('invalid key fails @fetchfox @sanity', async () => {
17
+ const fox = new FetchFox({
18
+ apiKey: 'invalid',
19
+ });
20
+
21
+ let err;
22
+ try {
23
+ await fox.crawl({
24
+ pattern: 'https://pokemondb.net/pokedex/*',
25
+ maxVisits: 5,
26
+ });
27
+ } catch (e) {
28
+ err = e;
29
+ }
30
+
31
+ expect(err).toBeTruthy();
32
+ }, 30_000);
@@ -0,0 +1,9 @@
1
+ import { FetchFox } from '../src';
2
+
3
+ test('use object @sanity', async () => {
4
+ const fox = new FetchFox({
5
+ apiKey: process.env.FETCHFOX_API_KEY,
6
+ });
7
+
8
+ console.log('fox', fox);
9
+ });