@spider-cloud/spider-client 0.0.11 → 0.0.12

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
@@ -25,13 +25,13 @@ Before using the SDK, you will need to provide it with your API key. Obtain an A
25
25
  Here's a basic example to demonstrate how to use the SDK:
26
26
 
27
27
  ```javascript
28
- import Spider from "spider-client";
28
+ import Spider from "@spider-cloud/spider-client";
29
29
 
30
30
  // Initialize the SDK with your API key
31
- const app = new Spider("your_api_key");
31
+ const app = new Spider({ apiKey: "YOUR_API_KEY" });
32
32
 
33
33
  // Scrape a URL
34
- const url = "https://spiderwebai.xyz";
34
+ const url = "https://spider.cloud";
35
35
  app
36
36
  .scrapeUrl(url)
37
37
  .then((data) => {
@@ -1,103 +1,23 @@
1
1
  /// <reference types="node" />
2
- /**
3
- * Configuration interface for Spider.
4
- */
5
2
  export interface SpiderConfig {
6
3
  apiKey?: string | null;
7
4
  }
8
- /**
9
- * A class to interact with the Spider API.
10
- */
11
5
  export default class Spider {
12
6
  private apiKey?;
13
- /**
14
- * Create an instance of Spider.
15
- * @param {string | null} apiKey - The API key used to authenticate to the Spider API. If null, attempts to source from environment variables.
16
- * @throws Will throw an error if the API key is not provided.
17
- */
18
7
  constructor({ apiKey }: SpiderConfig);
19
- /**
20
- * Internal method to handle POST requests.
21
- * @param {string} endpoint - The API endpoint to which the POST request should be sent.
22
- * @param {Record<string, any>} data - The JSON data to be sent in the request body.
23
- * @param {boolean} [stream=false] - Whether to stream the response back without parsing.
24
- * @returns {Promise<Response | any>} The response in JSON if not streamed, or the Response object if streamed.
25
- */
26
8
  private _apiPost;
27
- /**
28
- * Internal method to handle GET requests.
29
- * @param {string} endpoint - The API endpoint from which data should be retrieved.
30
- * @returns {Promise<any>} The data returned from the endpoint in JSON format.
31
- */
32
9
  private _apiGet;
33
- /**
34
- * Scrapes data from a specified URL.
35
- * @param {string} url - The URL to scrape.
36
- * @param {object} [params={}] - Additional parameters for the scraping request.
37
- * @returns {Promise<any>} The scraped data from the URL.
38
- */
39
10
  scrapeUrl(url: string, params?: {}): Promise<unknown>;
40
- /**
41
- * Initiates a crawling job starting from the specified URL.
42
- * @param {string} url - The URL to start crawling.
43
- * @param {object} [params={}] - Additional parameters for the crawl.
44
- * @param {boolean} [stream=false] - Whether to receive the response as a stream.
45
- * @returns {Promise<any | Response>} The result of the crawl, either structured data or a Response object if streaming.
46
- */
47
11
  crawlUrl(url: string, params?: {}, stream?: boolean): Promise<unknown>;
48
- /**
49
- * Retrieves all links from the specified URL.
50
- * @param {string} url - The URL from which to gather links.
51
- * @param {object} [params={}] - Additional parameters for the request.
52
- * @returns {Promise<any>} A list of links extracted from the URL.
53
- */
54
12
  links(url: string, params?: {}): Promise<unknown>;
55
- /**
56
- * Takes a screenshot of the specified URL.
57
- * @param {string} url - The URL to screenshot.
58
- * @param {object} [params={}] - Configuration parameters for the screenshot.
59
- * @returns {Promise<any>} The screenshot data.
60
- */
61
13
  screenshot(url: string, params?: {}): Promise<unknown>;
62
- /**
63
- * Extracts contact information from the specified URL.
64
- * @param {string} url - The URL from which to extract contacts.
65
- * @param {object} [params={}] - Configuration parameters for the extraction.
66
- * @returns {Promise<any>} The contact information extracted.
67
- */
68
14
  extractContacts(url: string, params?: {}): Promise<unknown>;
69
- /**
70
- * Applies labeling to data extracted from a specified URL.
71
- * @param {string} url - The URL to label.
72
- * @param {object} [params={}] - Configuration parameters for labeling.
73
- * @returns {Promise<any>} The labeled data.
74
- */
75
15
  label(url: string, params?: {}): Promise<unknown>;
76
- /**
77
- * Check the crawl state of the website.
78
- * @param {string} url - The URL to check.
79
- * @param {object} [params={}] - Configuration parameters for crawl state. Can also pass in "domain" instead of the url to query.
80
- * @returns {Promise<any>} The crawl state data.
81
- */
82
16
  getCrawlState(url: string, params?: {}): Promise<unknown>;
83
- /**
84
- * Retrieves the number of credits available on the account.
85
- * @returns {Promise<any>} The current credit balance.
86
- */
87
17
  getCredits(): Promise<unknown>;
88
- /**
89
- * Prepares common headers for each API request.
90
- * @returns {HeadersInit} A headers object for fetch requests.
91
- */
92
18
  prepareHeaders(): {
93
19
  "Content-Type": string;
94
20
  Authorization: string;
95
21
  };
96
- /**
97
- * Handles errors from API requests.
98
- * @param {Response} response - The fetch response object.
99
- * @param {string} action - Description of the attempted action.
100
- * @throws Will throw an error with detailed status information.
101
- */
102
22
  handleError(response: Response, action: string): void;
103
23
  }
@@ -1,27 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * A class to interact with the Spider API.
5
- */
6
- class Spider {
7
- /**
8
- * Create an instance of Spider.
9
- * @param {string | null} apiKey - The API key used to authenticate to the Spider API. If null, attempts to source from environment variables.
10
- * @throws Will throw an error if the API key is not provided.
11
- */
1
+ export default class Spider {
12
2
  constructor({ apiKey = null }) {
13
- this.apiKey = apiKey || process?.env?.SPIDER_API_KEY;
3
+ var _a;
4
+ this.apiKey = apiKey || ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.SPIDER_API_KEY);
14
5
  if (!this.apiKey) {
15
6
  throw new Error("No API key provided");
16
7
  }
17
8
  }
18
- /**
19
- * Internal method to handle POST requests.
20
- * @param {string} endpoint - The API endpoint to which the POST request should be sent.
21
- * @param {Record<string, any>} data - The JSON data to be sent in the request body.
22
- * @param {boolean} [stream=false] - Whether to stream the response back without parsing.
23
- * @returns {Promise<Response | any>} The response in JSON if not streamed, or the Response object if streamed.
24
- */
25
9
  async _apiPost(endpoint, data, stream = false) {
26
10
  const headers = this.prepareHeaders();
27
11
  const response = await fetch(`https://api.spider.cloud/v1/${endpoint}`, {
@@ -39,11 +23,6 @@ class Spider {
39
23
  }
40
24
  return response;
41
25
  }
42
- /**
43
- * Internal method to handle GET requests.
44
- * @param {string} endpoint - The API endpoint from which data should be retrieved.
45
- * @returns {Promise<any>} The data returned from the endpoint in JSON format.
46
- */
47
26
  async _apiGet(endpoint) {
48
27
  const headers = this.prepareHeaders();
49
28
  const response = await fetch(`https://api.spider.cloud/v1/${endpoint}`, {
@@ -57,95 +36,38 @@ class Spider {
57
36
  this.handleError(response, `get from ${endpoint}`);
58
37
  }
59
38
  }
60
- /**
61
- * Scrapes data from a specified URL.
62
- * @param {string} url - The URL to scrape.
63
- * @param {object} [params={}] - Additional parameters for the scraping request.
64
- * @returns {Promise<any>} The scraped data from the URL.
65
- */
66
39
  async scrapeUrl(url, params = {}) {
67
40
  return this._apiPost("crawl", { url: url, limit: 1, ...params });
68
41
  }
69
- /**
70
- * Initiates a crawling job starting from the specified URL.
71
- * @param {string} url - The URL to start crawling.
72
- * @param {object} [params={}] - Additional parameters for the crawl.
73
- * @param {boolean} [stream=false] - Whether to receive the response as a stream.
74
- * @returns {Promise<any | Response>} The result of the crawl, either structured data or a Response object if streaming.
75
- */
76
42
  async crawlUrl(url, params = {}, stream = false) {
77
43
  return this._apiPost("crawl", { url: url, ...params }, stream);
78
44
  }
79
- /**
80
- * Retrieves all links from the specified URL.
81
- * @param {string} url - The URL from which to gather links.
82
- * @param {object} [params={}] - Additional parameters for the request.
83
- * @returns {Promise<any>} A list of links extracted from the URL.
84
- */
85
45
  async links(url, params = {}) {
86
46
  return this._apiPost("links", { url: url, ...params });
87
47
  }
88
- /**
89
- * Takes a screenshot of the specified URL.
90
- * @param {string} url - The URL to screenshot.
91
- * @param {object} [params={}] - Configuration parameters for the screenshot.
92
- * @returns {Promise<any>} The screenshot data.
93
- */
94
48
  async screenshot(url, params = {}) {
95
49
  return this._apiPost("screenshot", { url: url, ...params });
96
50
  }
97
- /**
98
- * Extracts contact information from the specified URL.
99
- * @param {string} url - The URL from which to extract contacts.
100
- * @param {object} [params={}] - Configuration parameters for the extraction.
101
- * @returns {Promise<any>} The contact information extracted.
102
- */
103
51
  async extractContacts(url, params = {}) {
104
52
  return this._apiPost("pipeline/extract-contacts", { url: url, ...params });
105
53
  }
106
- /**
107
- * Applies labeling to data extracted from a specified URL.
108
- * @param {string} url - The URL to label.
109
- * @param {object} [params={}] - Configuration parameters for labeling.
110
- * @returns {Promise<any>} The labeled data.
111
- */
112
54
  async label(url, params = {}) {
113
55
  return this._apiPost("pipeline/label", { url: url, ...params });
114
56
  }
115
- /**
116
- * Check the crawl state of the website.
117
- * @param {string} url - The URL to check.
118
- * @param {object} [params={}] - Configuration parameters for crawl state. Can also pass in "domain" instead of the url to query.
119
- * @returns {Promise<any>} The crawl state data.
120
- */
121
57
  async getCrawlState(url, params = {}) {
122
58
  return this._apiPost("crawl/status", { url: url, ...params });
123
59
  }
124
- /**
125
- * Retrieves the number of credits available on the account.
126
- * @returns {Promise<any>} The current credit balance.
127
- */
128
60
  async getCredits() {
129
61
  return this._apiGet("credits");
130
62
  }
131
- /**
132
- * Prepares common headers for each API request.
133
- * @returns {HeadersInit} A headers object for fetch requests.
134
- */
135
63
  prepareHeaders() {
136
64
  return {
137
65
  "Content-Type": "application/json",
138
66
  Authorization: `Bearer ${this.apiKey}`,
139
67
  };
140
68
  }
141
- /**
142
- * Handles errors from API requests.
143
- * @param {Response} response - The fetch response object.
144
- * @param {string} action - Description of the attempted action.
145
- * @throws Will throw an error with detailed status information.
146
- */
147
69
  handleError(response, action) {
148
70
  throw new Error(`Failed to ${action}. Status code: ${response.status}.`);
149
71
  }
150
72
  }
151
- exports.default = Spider;
73
+ //# sourceMappingURL=spiderwebai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spiderwebai.js","sourceRoot":"","sources":["../src/spiderwebai.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,OAAO,OAAO,MAAM;IAQzB,YAAY,EAAE,MAAM,GAAG,IAAI,EAAgB;;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,KAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,0CAAE,cAAc,CAAA,CAAC;QACrD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,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SAAS,CAAC,CAAC;IACjC,CAAC;IAMD,cAAc;QACZ,OAAO;YACL,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;SACvC,CAAC;IACJ,CAAC;IAQD,WAAW,CAAC,QAAkB,EAAE,MAAc;QAC5C,MAAM,IAAI,KAAK,CAAC,aAAa,MAAM,kBAAkB,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3E,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spider-cloud/spider-client",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "A Javascript SDK for Spider Cloud services",
5
5
  "scripts": {
6
6
  "test": "jest",