fetchfox-sdk 1.0.12 → 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 +1 -1
- package/src/#index.js# +13 -0
- package/src/detach.js +2 -0
- package/src/fetchfox.js +27 -0
- package/src/fetchfox.js~ +6 -0
- package/src/index.js +2 -1
- package/tests/fetchfox.test.js +32 -0
- package/tests/fetchfox.test.js~ +9 -0
package/package.json
CHANGED
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
package/src/fetchfox.js
ADDED
|
@@ -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
|
+
};
|
package/src/fetchfox.js~
ADDED
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 {
|
|
11
|
+
export { FetchFox } from './fetchfox.js';
|
|
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);
|