@spider-cloud/spider-client 0.1.22 → 0.1.24

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.
Files changed (2) hide show
  1. package/dist/client.js +10 -3
  2. package/package.json +8 -5
package/dist/client.js CHANGED
@@ -4,6 +4,7 @@ exports.Spider = void 0;
4
4
  const config_1 = require("./config");
5
5
  const package_json_1 = require("../package.json");
6
6
  const stream_reader_1 = require("./utils/stream-reader");
7
+ const exponential_backoff_1 = require("exponential-backoff");
7
8
  /**
8
9
  * A class to interact with the Spider API.
9
10
  */
@@ -29,10 +30,12 @@ class Spider {
29
30
  */
30
31
  async _apiPost(endpoint, data, stream, jsonl) {
31
32
  const headers = jsonl ? this.prepareHeadersJsonL : this.prepareHeaders;
32
- const response = await fetch(`${config_1.APISchema["url"]}/${config_1.ApiVersion.V1}/${endpoint}`, {
33
+ const response = await (0, exponential_backoff_1.backOff)(() => fetch(`${config_1.APISchema["url"]}/${config_1.ApiVersion.V1}/${endpoint}`, {
33
34
  method: "POST",
34
35
  headers: headers,
35
36
  body: JSON.stringify(data),
37
+ }), {
38
+ numOfAttempts: 5,
36
39
  });
37
40
  if (!stream) {
38
41
  if (response.ok) {
@@ -51,9 +54,11 @@ class Spider {
51
54
  */
52
55
  async _apiGet(endpoint) {
53
56
  const headers = this.prepareHeaders;
54
- const response = await fetch(`${config_1.APISchema["url"]}/${config_1.ApiVersion.V1}/${endpoint}`, {
57
+ const response = await (0, exponential_backoff_1.backOff)(() => fetch(`${config_1.APISchema["url"]}/${config_1.ApiVersion.V1}/${endpoint}`, {
55
58
  method: "GET",
56
59
  headers: headers,
60
+ }), {
61
+ numOfAttempts: 5,
57
62
  });
58
63
  if (response.ok) {
59
64
  return response.json();
@@ -69,9 +74,11 @@ class Spider {
69
74
  */
70
75
  async _apiDelete(endpoint) {
71
76
  const headers = this.prepareHeaders;
72
- const response = await fetch(`${config_1.APISchema["url"]}/${config_1.ApiVersion.V1}/${endpoint}`, {
77
+ const response = await (0, exponential_backoff_1.backOff)(() => fetch(`${config_1.APISchema["url"]}/${config_1.ApiVersion.V1}/${endpoint}`, {
73
78
  method: "DELETE",
74
79
  headers,
80
+ }), {
81
+ numOfAttempts: 5,
75
82
  });
76
83
  if (response.ok) {
77
84
  return response;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spider-cloud/spider-client",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "description": "Isomorphic Javascript SDK for Spider Cloud services",
5
5
  "scripts": {
6
6
  "test": "node --import tsx --test __tests__/*test.ts",
@@ -23,9 +23,12 @@
23
23
  "author": "Jeff Mendez<jeff@a11ywatch.com>",
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@types/node": "22.7.5",
27
- "dotenv": "^16.4.5",
28
- "tsx": "^4.19.1",
29
- "typescript": "5.6.3"
26
+ "@types/node": "22.10.1",
27
+ "dotenv": "^16.4.7",
28
+ "tsx": "^4.19.2",
29
+ "typescript": "5.7.2"
30
+ },
31
+ "dependencies": {
32
+ "exponential-backoff": "^3.1.1"
30
33
  }
31
34
  }