fetchfox-sdk 1.0.31 → 1.0.33

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.31",
3
+ "version": "1.0.33",
4
4
  "description": "AI scraper",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/api.js CHANGED
@@ -18,16 +18,12 @@ const FetchFoxAPIError = class extends Error {
18
18
  };
19
19
 
20
20
  export const call = async (method, path, params) => {
21
+ const headers = { 'Content-Type': 'application/json' };
21
22
  const key = apiKey(params);
22
-
23
- const args = {
24
- method,
25
- headers: {
26
- Authorization: `Bearer ${key}`,
27
- 'Content-Type': 'application/json',
28
- },
29
- };
30
-
23
+ if (key) {
24
+ headers['Authorization'] = `Bearer ${key}`;
25
+ }
26
+ const args = { method, headers };
31
27
  let url = endpoint(path, params);
32
28
  if (method == 'GET') {
33
29
  const clean = {};
package/src/configure.js CHANGED
@@ -26,6 +26,6 @@ export const host = (options) =>
26
26
  'https://api.fetchfox.ai';
27
27
 
28
28
  export const appHost = (options) =>
29
- host(options).replace('api.fetchfox.ai', 'app.fetchfox.ai');
29
+ host(options).replace('api.fetchfox.ai', 'fetchfox.ai');
30
30
 
31
31
  export const ws = (options) => host(options).replace('http', 'ws');
package/src/detach.js CHANGED
@@ -48,10 +48,12 @@ export const Job = class {
48
48
 
49
49
  if (!this.#completed && parsed.state == 'completed') {
50
50
  this.#completed = true;
51
+ this.trigger('completed', parsed);
51
52
  this.trigger('finished', parsed);
52
53
  }
53
54
  if (!this.#failed && parsed.state == 'failed') {
54
55
  this.#failed = true;
56
+ this.trigger('failed', parsed);
55
57
  this.trigger('finished', parsed);
56
58
  }
57
59
  };
@@ -141,6 +143,6 @@ export const Job = class {
141
143
  }
142
144
 
143
145
  async finished() {
144
- return this.waitFor('finished');
146
+ return Promise.race([this.completed(), this.failed()]);
145
147
  }
146
148
  };