fetchfox-sdk 1.0.24 → 1.0.25

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.24",
3
+ "version": "1.0.25",
4
4
  "description": "AI scraper",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/agent.js CHANGED
@@ -7,5 +7,5 @@ export async function agent(args) {
7
7
 
8
8
  agent.detach = async (args) => {
9
9
  const data = await call('POST', '/api/agent', { ...args, detach: true });
10
- return new Job(data.jobId, args);
10
+ return new Job('agent', data.jobId, args);
11
11
  };
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, args);
10
+ return new Job('crawl', data.jobId, args);
11
11
  };
package/src/detach.js CHANGED
@@ -15,7 +15,8 @@ export const Job = class {
15
15
  #completed;
16
16
  #failed;
17
17
 
18
- constructor(id, options) {
18
+ constructor(name, id, options) {
19
+ this.name = name;
19
20
  this.id = id;
20
21
  this.#callbacks = {
21
22
  item: [],
@@ -39,7 +40,9 @@ export const Job = class {
39
40
  }
40
41
 
41
42
  get appUrl() {
42
- return appHost() + '/jobs/' + this.id;
43
+ return [appHost(), this.name == 'agent' ? 'agents' : 'jobs', this.id].join(
44
+ '/'
45
+ );
43
46
  }
44
47
 
45
48
  #select(data) {
@@ -108,6 +111,8 @@ export const Job = class {
108
111
  }
109
112
 
110
113
  if (['completed', 'failed'].includes(this.state)) {
114
+ console.log('Got state:', this.state);
115
+
111
116
  if (this.progress?.children?.jobs) {
112
117
  this.progress.children.jobs = this.progress.children.jobs.filter(
113
118
  (it) => it.state != 'active'
@@ -116,13 +121,16 @@ export const Job = class {
116
121
 
117
122
  this.#socket.disconnect();
118
123
 
119
- this.get()
120
- .then(() => {
121
- this.trigger('progress', this);
122
- this.trigger(this.state, this);
123
- this.trigger('finished', this);
124
- })
125
- .catch((e) => console.error(e));
124
+ console.log('Set timeout before triggering completion');
125
+ setTimeout(() => {
126
+ this.get()
127
+ .then(() => {
128
+ this.trigger('progress', this);
129
+ this.trigger(this.state, this);
130
+ this.trigger('finished', this);
131
+ })
132
+ .catch((e) => console.error(e));
133
+ }, 500);
126
134
  }
127
135
  }
128
136
 
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, args);
10
+ return new Job('extract', 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, args);
10
+ return new Job('scrape', data.jobId, args);
11
11
  };