@spider-cloud/spider-client 0.0.20 → 0.0.21

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/dist/client.d.ts CHANGED
@@ -9,7 +9,6 @@ export interface SpiderConfig {
9
9
  */
10
10
  export declare class Spider {
11
11
  private apiKey?;
12
- private dataEndPoint;
13
12
  /**
14
13
  * Create an instance of Spider.
15
14
  * @param {string | null} apiKey - The API key used to authenticate to the Spider API. If null, attempts to source from environment variables.
@@ -30,6 +29,12 @@ export declare class Spider {
30
29
  * @returns {Promise<any>} The data returned from the endpoint in JSON format.
31
30
  */
32
31
  private _apiGet;
32
+ /**
33
+ * Internal method to handle DELETE requests.
34
+ * @param {string} endpoint - The API endpoint from which data should be retrieved.
35
+ * @returns {Promise<any>} The data returned from the endpoint in JSON format.
36
+ */
37
+ private _apiDelete;
33
38
  /**
34
39
  * Scrapes data from a specified URL.
35
40
  * @param {string} url - The URL to scrape.
@@ -106,7 +111,6 @@ export declare class Spider {
106
111
  * @returns {Promise<any>} The response from the server.
107
112
  */
108
113
  deleteData(table: string, params: object): Promise<any>;
109
- private _apiDataPost;
110
114
  /**
111
115
  * Prepares common headers for each API request.
112
116
  * @returns {HeadersInit} A headers object for fetch requests.
package/dist/client.js CHANGED
@@ -12,7 +12,6 @@ class Spider {
12
12
  */
13
13
  constructor(props) {
14
14
  var _a;
15
- this.dataEndPoint = "https://api.spider.cloud:3280";
16
15
  this.apiKey = (props === null || props === void 0 ? void 0 : props.apiKey) || ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.SPIDER_API_KEY);
17
16
  if (!this.apiKey) {
18
17
  throw new Error("No API key provided");
@@ -60,6 +59,24 @@ class Spider {
60
59
  this.handleError(response, `get from ${endpoint}`);
61
60
  }
62
61
  }
62
+ /**
63
+ * Internal method to handle DELETE requests.
64
+ * @param {string} endpoint - The API endpoint from which data should be retrieved.
65
+ * @returns {Promise<any>} The data returned from the endpoint in JSON format.
66
+ */
67
+ async _apiDelete(endpoint) {
68
+ const headers = this.prepareHeaders();
69
+ const response = await fetch(`https://api.spider.cloud/v1/${endpoint}`, {
70
+ method: "DELETE",
71
+ headers,
72
+ });
73
+ if (response.ok) {
74
+ return response.json();
75
+ }
76
+ else {
77
+ this.handleError(response, `get from ${endpoint}`);
78
+ }
79
+ }
63
80
  /**
64
81
  * Scrapes data from a specified URL.
65
82
  * @param {string} url - The URL to scrape.
@@ -138,8 +155,7 @@ class Spider {
138
155
  * @returns {Promise<any>} The response from the server.
139
156
  */
140
157
  async postData(table, data) {
141
- const endpoint = `/data/${table}`;
142
- return this._apiDataPost(endpoint, data);
158
+ return this._apiPost(`data/${table}`, data);
143
159
  }
144
160
  /**
145
161
  * Send a GET request to retrieve data from a specified table.
@@ -148,18 +164,7 @@ class Spider {
148
164
  * @returns {Promise<any>} The response from the server.
149
165
  */
150
166
  async getData(table, params) {
151
- const endpoint = `/data/${table}?${new URLSearchParams(params).toString()}`;
152
- const headers = this.prepareHeaders();
153
- const response = await fetch(`${this.dataEndPoint}${endpoint}`, {
154
- method: "GET",
155
- headers: headers,
156
- });
157
- if (response.ok) {
158
- return response.json();
159
- }
160
- else {
161
- this.handleError(response, `get data from ${table}`);
162
- }
167
+ return this._apiGet(`data/${table}?${new URLSearchParams(params).toString()}`);
163
168
  }
164
169
  /**
165
170
  * Send a DELETE request to remove data from a specified table.
@@ -168,33 +173,7 @@ class Spider {
168
173
  * @returns {Promise<any>} The response from the server.
169
174
  */
170
175
  async deleteData(table, params) {
171
- const endpoint = `/data/${table}?${new URLSearchParams(params).toString()}`;
172
- const headers = this.prepareHeaders();
173
- const response = await fetch(`${this.dataEndPoint}${endpoint}`, {
174
- method: "DELETE",
175
- headers,
176
- });
177
- if (response.ok) {
178
- return response.json();
179
- }
180
- else {
181
- this.handleError(response, `delete data from ${table}`);
182
- }
183
- }
184
- // Create wrapper methods for external API access:
185
- async _apiDataPost(endpoint, data) {
186
- const headers = this.prepareHeaders();
187
- const response = await fetch(`${this.dataEndPoint}${endpoint}`, {
188
- method: "POST",
189
- headers,
190
- body: JSON.stringify(data),
191
- });
192
- if (response.ok) {
193
- return response.json();
194
- }
195
- else {
196
- this.handleError(response, `post to ${endpoint}`);
197
- }
176
+ return this._apiDelete(`data/${table}?${new URLSearchParams(params).toString()}`);
198
177
  }
199
178
  /**
200
179
  * Prepares common headers for each API request.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spider-cloud/spider-client",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "A Javascript SDK for Spider Cloud services",
5
5
  "scripts": {
6
6
  "test": "jest",