@spider-cloud/spider-client 0.0.58 → 0.0.59

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/README.md CHANGED
@@ -176,4 +176,4 @@ Contributions are always welcome! Feel free to open an issue or submit a pull re
176
176
 
177
177
  ## License
178
178
 
179
- The Spider Cloud JavaScript SDK is open-source and released under the [MIT License](https://opensource.org/licenses/MIT).
179
+ The Spider Cloud JavaScript SDK is open-source and released under the [MIT License](https://opensource.org/licenses/MIT).
package/dist/client.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { ChunkCallbackFunction, QueryRequest, SpiderCoreResponse, SpiderParams } from "./config";
1
+ import { ChunkCallbackFunction, Collection, QueryRequest, SpiderCoreResponse, SpiderParams } from "./config";
2
+ export declare const BASE_API_URL = "https://api.spider.cloud";
2
3
  /**
3
4
  * Generic params for core request.
4
5
  */
@@ -124,11 +125,13 @@ export declare class Spider {
124
125
 
125
126
  * @returns {Promise<Response>} The response containing the file stream.
126
127
  */
127
- createSignedUrl(domain?: string, options?: {
128
+ createSignedUrl(url?: string, options?: {
128
129
  page?: number;
129
130
  limit?: number;
130
131
  expiresIn?: number;
131
- }, raw?: boolean): Promise<Response>;
132
+ domain?: string;
133
+ pathname?: string;
134
+ }): Promise<any>;
132
135
  /**
133
136
  * Retrieves the number of credits available on the account.
134
137
  * @returns {Promise<any>} The current credit balance.
@@ -143,11 +146,17 @@ export declare class Spider {
143
146
  postData(table: string, data: GenericParams | Record<string, any>): Promise<any>;
144
147
  /**
145
148
  * Send a GET request to retrieve data from a specified table.
146
- * @param {string} table - The table name in the database.
149
+ * @param {Collection} table - The table name in the database.
147
150
  * @param {object} params - The query parameters for data retrieval.
148
151
  * @returns {Promise<any>} The response from the server.
149
152
  */
150
- getData(table: string, params: GenericParams | Record<string, any>): Promise<any>;
153
+ getData(collections: Collection, params: GenericParams | Record<string, any>): Promise<any>;
154
+ /**
155
+ * Download a record. The url is the path of the storage hash returned and not the exact website url.
156
+ * @param {QueryRequest} params - The query parameters for data retrieval.
157
+ * @returns {Promise<any>} The download response from the server.
158
+ */
159
+ download(query: QueryRequest, output?: "text" | "blob"): Promise<any>;
151
160
  /**
152
161
  * Perform a query to get a document.
153
162
  * @param {QueryRequest} params - The query parameters for data retrieval.
@@ -156,11 +165,11 @@ export declare class Spider {
156
165
  query(query: QueryRequest): Promise<any>;
157
166
  /**
158
167
  * Send a DELETE request to remove data from a specified table.
159
- * @param {string} table - The table name in the database.
168
+ * @param {Collection} table - The table name in the database.
160
169
  * @param {object} params - Parameters to identify records to delete.
161
170
  * @returns {Promise<any>} The response from the server.
162
171
  */
163
- deleteData(table: string, params: GenericParams | Record<string, any>): Promise<any>;
172
+ deleteData(collection: Collection, params: GenericParams | Record<string, any>): Promise<any>;
164
173
  /**
165
174
  * Prepares common headers for each API request.
166
175
  * @returns {HeadersInit} A headers object for fetch requests.
package/dist/client.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Spider = void 0;
3
+ exports.Spider = exports.BASE_API_URL = void 0;
4
4
  const package_json_1 = require("../package.json");
5
5
  const supabase_1 = require("./supabase");
6
6
  const stream_reader_1 = require("./utils/stream-reader");
7
+ exports.BASE_API_URL = "https://api.spider.cloud";
7
8
  /**
8
9
  * A class to interact with the Spider API.
9
10
  */
@@ -41,7 +42,7 @@ class Spider {
41
42
  */
42
43
  async _apiPost(endpoint, data, stream, jsonl) {
43
44
  const headers = jsonl ? this.prepareHeadersJsonL : this.prepareHeaders;
44
- const response = await fetch(`https://api.spider.cloud/v1/${endpoint}`, {
45
+ const response = await fetch(`${exports.BASE_API_URL}/v1/${endpoint}`, {
45
46
  method: "POST",
46
47
  headers: headers,
47
48
  body: JSON.stringify(data),
@@ -63,7 +64,7 @@ class Spider {
63
64
  */
64
65
  async _apiGet(endpoint) {
65
66
  const headers = this.prepareHeaders;
66
- const response = await fetch(`https://api.spider.cloud/v1/${endpoint}`, {
67
+ const response = await fetch(`${exports.BASE_API_URL}/v1/${endpoint}`, {
67
68
  method: "GET",
68
69
  headers: headers,
69
70
  });
@@ -81,7 +82,7 @@ class Spider {
81
82
  */
82
83
  async _apiDelete(endpoint) {
83
84
  const headers = this.prepareHeaders;
84
- const response = await fetch(`https://api.spider.cloud/v1/${endpoint}`, {
85
+ const response = await fetch(`${exports.BASE_API_URL}/v1/${endpoint}`, {
85
86
  method: "DELETE",
86
87
  headers,
87
88
  });
@@ -188,36 +189,35 @@ class Spider {
188
189
 
189
190
  * @returns {Promise<Response>} The response containing the file stream.
190
191
  */
191
- async createSignedUrl(domain, options, raw) {
192
- const { page, limit, expiresIn } = options !== null && options !== void 0 ? options : {};
192
+ async createSignedUrl(url, options) {
193
+ const { page, limit, expiresIn, domain, pathname } = options !== null && options !== void 0 ? options : {};
193
194
  const params = new URLSearchParams({
195
+ ...(url && { url }),
194
196
  ...(domain && { domain }),
197
+ ...(pathname && { pathname }),
195
198
  ...(page && { page: page.toString() }),
196
199
  ...(limit && { limit: limit.toString() }),
197
200
  ...(expiresIn && { expiresIn: expiresIn.toString() }),
198
201
  });
199
- const endpoint = `https://api.spider.cloud/v1/data/storage?${params.toString()}`;
202
+ const endpoint = `${exports.BASE_API_URL}/data/sign-url?${params.toString()}`;
200
203
  const headers = this.prepareHeaders;
201
204
  const response = await fetch(endpoint, {
202
205
  method: "GET",
203
206
  headers,
204
207
  });
205
- if (!raw) {
206
- if (response.ok) {
207
- return response.json();
208
- }
209
- else {
210
- this.handleError(response, `Failed to download files`);
211
- }
208
+ if (response.ok) {
209
+ return await response.json();
210
+ }
211
+ else {
212
+ this.handleError(response, `Failed to download files`);
212
213
  }
213
- return response;
214
214
  }
215
215
  /**
216
216
  * Retrieves the number of credits available on the account.
217
217
  * @returns {Promise<any>} The current credit balance.
218
218
  */
219
219
  async getCredits() {
220
- return this._apiGet("credits");
220
+ return this._apiGet("data/credits");
221
221
  }
222
222
  /**
223
223
  * Send a POST request to insert data into a specified table.
@@ -230,12 +230,34 @@ class Spider {
230
230
  }
231
231
  /**
232
232
  * Send a GET request to retrieve data from a specified table.
233
- * @param {string} table - The table name in the database.
233
+ * @param {Collection} table - The table name in the database.
234
234
  * @param {object} params - The query parameters for data retrieval.
235
235
  * @returns {Promise<any>} The response from the server.
236
236
  */
237
- async getData(table, params) {
238
- return this._apiGet(`data/${table}?${new URLSearchParams(params).toString()}`);
237
+ async getData(collections, params) {
238
+ return this._apiGet(`data/${collections}?${new URLSearchParams(params).toString()}`);
239
+ }
240
+ /**
241
+ * Download a record. The url is the path of the storage hash returned and not the exact website url.
242
+ * @param {QueryRequest} params - The query parameters for data retrieval.
243
+ * @returns {Promise<any>} The download response from the server.
244
+ */
245
+ async download(query, output) {
246
+ const headers = this.prepareHeaders;
247
+ const endpoint = `data/download?${new URLSearchParams(query).toString()}`;
248
+ const response = await fetch(`${exports.BASE_API_URL}/v1/${endpoint}`, {
249
+ method: "GET",
250
+ headers,
251
+ });
252
+ if (response.ok) {
253
+ if (output === "text") {
254
+ return await response.text();
255
+ }
256
+ return await response.blob();
257
+ }
258
+ else {
259
+ this.handleError(response, `get from ${endpoint}`);
260
+ }
239
261
  }
240
262
  /**
241
263
  * Perform a query to get a document.
@@ -247,12 +269,12 @@ class Spider {
247
269
  }
248
270
  /**
249
271
  * Send a DELETE request to remove data from a specified table.
250
- * @param {string} table - The table name in the database.
272
+ * @param {Collection} table - The table name in the database.
251
273
  * @param {object} params - Parameters to identify records to delete.
252
274
  * @returns {Promise<any>} The response from the server.
253
275
  */
254
- async deleteData(table, params) {
255
- return this._apiDelete(`data/${table}?${new URLSearchParams(params).toString()}`);
276
+ async deleteData(collection, params) {
277
+ return this._apiDelete(`data/${collection}?${new URLSearchParams(params).toString()}`);
256
278
  }
257
279
  /**
258
280
  * Prepares common headers for each API request.
package/dist/config.d.ts CHANGED
@@ -260,4 +260,16 @@ export type SpiderCoreResponse = {
260
260
  url?: string;
261
261
  };
262
262
  export type ChunkCallbackFunction = (data: SpiderCoreResponse) => void;
263
+ export declare enum Collection {
264
+ Websites = "websites",
265
+ Pages = "pages",
266
+ PagesMetadata = "pages_metadata",
267
+ Contacts = "contacts",
268
+ CrawlState = "crawl_state",
269
+ CrawlLogs = "crawl_logs",
270
+ Profiles = "profiles",
271
+ Credits = "credits",
272
+ Webhooks = "webhooks",
273
+ APIKeys = "api_keys"
274
+ }
263
275
  export {};
package/dist/config.js CHANGED
@@ -1,2 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Collection = void 0;
4
+ // records that you can query
5
+ var Collection;
6
+ (function (Collection) {
7
+ Collection["Websites"] = "websites";
8
+ Collection["Pages"] = "pages";
9
+ Collection["PagesMetadata"] = "pages_metadata";
10
+ // Leads
11
+ Collection["Contacts"] = "contacts";
12
+ Collection["CrawlState"] = "crawl_state";
13
+ Collection["CrawlLogs"] = "crawl_logs";
14
+ Collection["Profiles"] = "profiles";
15
+ Collection["Credits"] = "credits";
16
+ Collection["Webhooks"] = "webhooks";
17
+ Collection["APIKeys"] = "api_keys";
18
+ })(Collection || (exports.Collection = Collection = {}));
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { Spider } from "./client";
2
2
  export type { SpiderParams, Budget, Viewport, QueryRequest } from "./config";
3
+ export { Collection } from "./config";
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Spider = void 0;
3
+ exports.Collection = exports.Spider = void 0;
4
4
  var client_1 = require("./client");
5
5
  Object.defineProperty(exports, "Spider", { enumerable: true, get: function () { return client_1.Spider; } });
6
+ var config_1 = require("./config");
7
+ Object.defineProperty(exports, "Collection", { enumerable: true, get: function () { return config_1.Collection; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spider-cloud/spider-client",
3
- "version": "0.0.58",
3
+ "version": "0.0.59",
4
4
  "description": "Isomorphic Javascript SDK for Spider Cloud services",
5
5
  "scripts": {
6
6
  "test": "node --import tsx --test __tests__/*test.ts",