webcrawlerapi-js 1.1.4 → 1.1.6

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.
@@ -1,4 +1,4 @@
1
- import { CrawlRequest, Job, JobId, ScrapeRequest, ScrapeResponse } from "./model";
1
+ import { CrawlRequest, Job, JobId, ScrapeRequest, ScrapeResponse, Action } from "./model";
2
2
  import { JobStatus } from "./constants";
3
3
  import { WebcrawlerApiError } from "./errors";
4
4
  export { WebcrawlerApiError, JobStatus };
@@ -12,8 +12,8 @@ export declare class WebcrawlerClient {
12
12
  scrapeWithMeta(scrapeRequest: ScrapeRequest, maxPollingRetries?: number): Promise<ScrapeResponse>;
13
13
  scrape(scrapeRequest: ScrapeRequest, maxPollingRetries?: number): Promise<any>;
14
14
  getScrapeResult(scrapeID: string): Promise<ScrapeResponse>;
15
- crawl(crawlRequest: CrawlRequest): Promise<Job>;
16
- crawlAsync(crawlRequest: CrawlRequest): Promise<JobId>;
15
+ crawl(crawlRequest: CrawlRequest, actions?: Action | Action[]): Promise<Job>;
16
+ crawlAsync(crawlRequest: CrawlRequest, actions?: Action | Action[]): Promise<JobId>;
17
17
  getJob(jobID: string): Promise<Job>;
18
18
  private sendRequest;
19
19
  }
@@ -18,7 +18,7 @@ export interface ScrapeResponse {
18
18
  recommended_pull_delay_ms: number;
19
19
  }
20
20
  export interface CrawlRequest {
21
- url: string;
21
+ url?: string;
22
22
  crawler_id?: string;
23
23
  items_limit?: number;
24
24
  scrape_type?: string;
@@ -26,6 +26,7 @@ export interface CrawlRequest {
26
26
  blacklist_regexp?: string;
27
27
  allow_subdomains?: boolean;
28
28
  webhook_url?: string;
29
+ actions?: Action[];
29
30
  }
30
31
  export interface Job {
31
32
  id: string;
@@ -61,3 +62,14 @@ export interface JobItem {
61
62
  cleaned_content_url?: string;
62
63
  getContent(): Promise<string | null>;
63
64
  }
65
+ export interface Action {
66
+ type: string;
67
+ }
68
+ export interface UploadS3Action extends Action {
69
+ type: 'upload_s3';
70
+ path: string;
71
+ access_key_id: string;
72
+ secret_access_key: string;
73
+ bucket: string;
74
+ endpoint?: string;
75
+ }
package/dist/api.js CHANGED
@@ -92,8 +92,12 @@ class WebcrawlerClient {
92
92
  };
93
93
  return await this.sendRequest(url, requestOptions);
94
94
  }
95
- async crawl(crawlRequest) {
95
+ async crawl(crawlRequest, actions) {
96
96
  const url = `${this.basePath}/${this.apiVersion}/crawl`;
97
+ const requestBody = {
98
+ ...crawlRequest,
99
+ actions: actions ? (Array.isArray(actions) ? actions : [actions]) : undefined
100
+ };
97
101
  const requestOptions = {
98
102
  'method': 'POST',
99
103
  'headers': {
@@ -104,7 +108,7 @@ class WebcrawlerClient {
104
108
  'Pragma': 'no-cache',
105
109
  'Expires': '0'
106
110
  },
107
- 'body': JSON.stringify(crawlRequest),
111
+ 'body': JSON.stringify(requestBody),
108
112
  };
109
113
  const jobIdResponse = await this.sendRequest(url, requestOptions);
110
114
  if (jobIdResponse.id === '') {
@@ -158,15 +162,19 @@ class WebcrawlerClient {
158
162
  }
159
163
  throw new errors_1.WebcrawlerApiError('timeout', 'Crawling took too long, please retry or increase the number of polling retries', 0);
160
164
  }
161
- async crawlAsync(crawlRequest) {
165
+ async crawlAsync(crawlRequest, actions) {
162
166
  const url = `${this.basePath}/${this.apiVersion}/crawl`;
167
+ const requestBody = {
168
+ ...crawlRequest,
169
+ actions: actions ? (Array.isArray(actions) ? actions : [actions]) : undefined
170
+ };
163
171
  const requestOptions = {
164
172
  'method': 'POST',
165
173
  'headers': {
166
174
  'Content-Type': 'application/json',
167
175
  'Authorization': `Bearer ${this.apiKey}`
168
176
  },
169
- 'body': JSON.stringify(crawlRequest),
177
+ 'body': JSON.stringify(requestBody),
170
178
  };
171
179
  return await this.sendRequest(url, requestOptions);
172
180
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webcrawlerapi-js",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
 
5
5
  "description": "JS client for WebcrawlerAPI",
6
6
  "main": "./dist/api.js",